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

40 lines
1.0 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# zoomer challenges
2016-04-02 01:22:47 +02:00
Coding challenges for the zoomer tutorial.#acceleration.
2016-03-26 00:47:20 +01:00
## Before we get started
2016-04-13 17:27:45 +02:00
Complete the following [guided tutorial](/lessons/zoomer/tutorial) and your finished code should look like this:
2016-03-26 00:47:20 +01:00
```
basic.forever(() => {
let az = input.acceleration("z")
basic.showNumber(az, 150)
})
```
### Challenge 1
### @video td/videos/zoomer-2
We'll modify the code to display the `x` acceleration if the `A` button is pressed. For that, we need to store `input->acceleration(x)` in a new variable `ax` and use a `input->button is pressed(A)` to detect if the button is pressed.
```
basic.forever(() => {
let az1 = input.acceleration("z")
let ax = input.acceleration("x")
if (input.buttonIsPressed("A")) {
basic.showNumber(ax, 150) // ***
} else {
basic.showNumber(az1, 150) // ***
}
})
```
* 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 `input->button is pressed(B)`.