pxt-calliope/docs/lessons/magic-8/tutorial.md

28 lines
774 B
Markdown
Raw Permalink Normal View History

2016-05-09 18:45:57 +02:00
# Magic 8 tutorial
Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer questions with "YES", "NO", or "MAYBE"...
### Rebuild the game!
The blocks have been shuffled! Put them back together so that...
* show "ASK A QUESTION" on the screen
2016-11-02 01:44:37 +01:00
* when the @boardname@ is shaken,
2016-05-09 18:45:57 +02:00
* generate a random number between 0 and 2.
* if the number is `2`, show "YES"
* if the number is `1`, show "NO"
* otherwise show "MAYBE"...
```shuffle
basic.showString("ASK A QUESTION")
input.onGesture(Gesture.Shake, () => {
let randomNumber = Math.random(3)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
} else {
basic.showString("MAYBE")
}
})
```