pxt-calliope/olddocs/js/lessons/on-shake/challenges.md

82 lines
1.6 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# flipping bird challenges
2016-11-02 01:44:37 +01:00
These challenges will allow you to create and display a flipping image of a bird when the @boardname@ is shaken. #docs
2016-03-26 00:47:20 +01:00
### Challenge 0
2016-04-13 17:27:45 +02:00
Greetings! This [guided tutorial](/lessons/flipping-bird/tutorial) will begin to show you how to flip a bird.
2016-03-26 00:47:20 +01:00
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
images.createImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`).showImage(0)
}
})
```
### Challenge 1
We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
images.createImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`).showImage(0)
}
if (math.mod(counter, 2) == 0) {
}
})
```
### Challenge 2
Inside of that `if` statement you created in challenge 1, add `image->create image()->show image(0)` and display an upside down flying bird.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
images.createImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`).showImage(0)
}
if (math.mod(counter, 2) == 0) {
images.createImage(`
. . . . .
. . . . .
. . . . .
. . # . .
# # . # #
`).showImage(0) // ***
}
})
```
* Run the code to see if it works as expected.
### Challenge 3
Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display!