2016-03-25 16:47:20 -07:00
# guess the number activity
Guess the number with math random.
2017-09-07 13:42:08 -07:00
## ~avatar avatar
2016-03-25 16:47:20 -07:00
Welcome! This tutorial will help you create a guess the number game! Let's get started!
2017-09-07 13:42:08 -07:00
## ~
2016-03-25 16:47:20 -07:00
Add an event handler when button `A` is pressed.
```blocks
input.onButtonPressed(Button.A, () => {
})
```
2016-05-09 10:32:02 -07:00
Create a local variable of type number `x` and set it to a random number using `pick random` . `pick random` 9 generates a random number between `0` and `9` .
2016-03-25 16:47:20 -07:00
```blocks
input.onButtonPressed(Button.A, () => {
2018-06-01 11:42:38 -07:00
let x = Math.randomRange(0, 10)
2016-03-25 16:47:20 -07:00
})
```
Show the random number on the screen.
```blocks
input.onButtonPressed(Button.A, () => {
2018-06-01 11:42:38 -07:00
let x = Math.randomRange(0, 10)
2016-03-25 16:47:20 -07:00
basic.showNumber(x)
})
```
2017-09-07 13:42:08 -07:00
## ~avatar avatar
2016-03-25 16:47:20 -07:00
2016-04-13 08:27:45 -07:00
Excellent, you're ready to continue with the [challenges ](/lessons/guess-the-number/challenges )!
2016-03-25 16:47:20 -07:00
2017-09-07 13:42:08 -07:00
## ~
2016-03-25 16:47:20 -07:00