pxt-calliope/docs/lessons/guess-the-number/quiz-answers.md

42 lines
1.1 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# guess the number quiz answers
2016-04-02 01:22:47 +02:00
Learn how to generate a random number on the micro:bit.
2016-03-26 00:47:20 +01:00
2016-04-13 17:27:45 +02:00
This is the answer key for the [guess the number quiz](/lessons/guess-the-number/quiz).
2016-03-26 00:47:20 +01:00
## 1. What is on button pressed?
Answers may vary. Generally, on button pressed run code when an input button is pressed. The micro:bit has two input buttons: A and B.
## 2. Consider the following directions
Write the line of code that creates a condition when the BBC micro:bit button A is pressed.
2016-03-30 20:15:31 +02:00
2016-03-30 01:24:11 +02:00
```blocks
2016-03-30 20:15:31 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
})
```
2016-03-30 20:15:31 +02:00
## 3. Write the line of code that creates a **local variable** and a **random number**.
2016-03-26 00:47:20 +01:00
2016-03-30 01:24:11 +02:00
```blocks
2016-03-26 00:47:20 +01:00
let randomNumber = Math.random(10)
```
2016-03-30 20:15:31 +02:00
## 4.
If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded.
2016-03-26 00:47:20 +01:00
2016-03-30 01:24:11 +02:00
```blocks
2016-03-31 00:54:19 +02:00
let randomNumber = Math.random(10)
2016-03-26 00:47:20 +01:00
```
![](/static/mb/lessons/guess-the-number-0.png)
The random number generator will return a number from 0 to the limit. However, not including the limit unless the limit is 0. So you can place an X to represent any single digit number.