pxt-calliope/olddocs/js/lessons/yes-no/challenges.md

46 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2016-03-26 00:47:20 +01:00
# yes no challenges
My script. #docs
**Challenge 0**
2016-11-02 01:44:37 +01:00
This [guided tutorial](/lessons/yes-no/challenges) will show you how to display text on the @boardname@!
2016-03-26 00:47:20 +01:00
```
basic.showString("ASK ME A QUESTION", 150)
```
**Challenge 1**
Now we need to reply after someone asks Micro a yes or no question. We want to respond `YES` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YES`.
```
basic.showString("ASK ME A QUESTION", 150)
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
basic.showString("YES", 150) // ***
}) // ***
```
* `Run` the code to see if it works as expected.
**Challenge 2**
What if Micro's answer to the question is no? Let's have `NO` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the string `NO`.
```
basic.showString("ASK ME A QUESTION", 150)
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
basic.showString("YES", 150)
})
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
basic.showString("NO", 150) // ***
}) // ***
```
* `Run` the code to see if it works as expected.
**Challenge 3**
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `MAYBE`.