pxt-calliope/docs/lessons/offset-image/quiz-answers.md

49 lines
1.1 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# offset image quiz answers
2016-04-02 01:22:47 +02:00
shift an image horizontally across the display with offset.
2016-03-26 00:47:20 +01:00
2016-04-13 17:27:45 +02:00
This is the answer key for the [offset image quiz](/lessons/offset-image/quiz).
2016-03-26 00:47:20 +01:00
## 1. What is a 'if, then, else statement' ?
<br/>
An if-then statement will run a block of code if the condition specified is true. The statement will run the "else" block of code if that condition is false.
## 2. Consider the message
Write the line of code that that will create the message "Push button A" (Hint: This message appears `if` the offset is equal -4 then the BBC micro:bit will state "Push Button A").
<br/>
```
if (offset == -4) {
basic.showString("Push Button A", 150)
}
```
## 3. Consider the following image
![](/static/mb/lessons/offset-image-0.png)
When with this image be displayed?
<br/>
When the offset is NOT equal to -4 then the BBC micro:bit will show the image above.
## 4. Consider the following image
![](/static/mb/lessons/offset-image-1.png)
Write the two lines of code that cause the `variable` offset to increase by one when button `A` is pressed.
<br/>
```
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
offset = offset + 1
})
```