Migrate docs from the other repo
This commit is contained in:
39
docs/lessons/game-counter/challenges.md
Normal file
39
docs/lessons/game-counter/challenges.md
Normal file
@ -0,0 +1,39 @@
|
||||
# game counter challenges
|
||||
|
||||
Coding challenges for the game counter.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [activity](/microbit/lessons/game-counter/activity) . Your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/counter-1-2
|
||||
|
||||
Let's add the code to `score` when `B` is pressed. Add an event handler with `on button (B) pressed` then add the code to `score`.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
game.addScore(-1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's try to reset the counter when the micro:bit is shaken. You will need to register an event handler with `on shake`.
|
||||
|
Reference in New Issue
Block a user