pxt-calliope/olddocs/js/lessons/clear-screen/challenges.md

78 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

2016-03-26 00:47:20 +01:00
# clear screen challenges
My script. #docs
### Challenge 0
2016-04-13 17:27:45 +02:00
Welcome! This [guided tutorial](/hzckbb) will help you create the script to clear the screen!
2016-03-26 00:47:20 +01:00
Your goal is to clear the screen after displaying an animation. Begin by showing and displaying an animation. Remember that the `show animation` is in the `basic` namespace. We then need to detect when the "A" button is pressed. Finally, clear the screen by typing in `basic->clear screen`.
Your main function should look like this:
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
basic.clearScreen()
})
```
* tap the `run` button to view the script on the monitor.
### Challenge 1
Create an event handler for Button "B".
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
basic.clearScreen()
})
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
})
```
### Challenge 2
Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
basic.clearScreen()
})
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400) // ***
})
```
### Challenge 3
Show an animation that scrolls back up when you press button "B".
* tap the `run` button to view your final product!