pxt-calliope/docs/lessons/zoomer/challenges.md

38 lines
956 B
Markdown
Raw Permalink Normal View History

2016-03-26 00:47:20 +01:00
# zoomer blocks challenges
Coding challenges for zoomer.
## Before we get started
2016-04-13 17:27:45 +02:00
Complete the following [activity](/lessons/zoomer/activity) and your finished code should look like this:
2016-03-26 00:47:20 +01:00
```blocks
basic.forever(() => {
let az = input.acceleration(Dimension.Z)
basic.showNumber(az)
})
```
### Challenge 1
2016-05-27 00:24:10 +02:00
2016-03-26 00:47:20 +01:00
We'll modify the code to display the `x` acceleration if the `A` button is pressed. For that, we need to store `acceleration (x)` in a new variable `ax` and use a `button (A) is pressed` to detect if the button is pressed.
```blocks
basic.forever(() => {
let az = input.acceleration(Dimension.Z)
let ax = input.acceleration(Dimension.X)
if (input.buttonIsPressed(Button.A)) {
basic.showNumber(ax)
}
basic.showNumber(az)
})
```
* Run the code to see if it works as expected.
### Challenge 2
Display the `y` acceleration when `B` is pressed by adding another `if` statement using `button (B) is pressed`.