2016-03-26 00:47:20 +01:00
|
|
|
# love meter blocks quiz answers
|
|
|
|
|
|
|
|
The answers to the love meter quiz.
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
This is the answer key for the [love meter quiz](/lessons/love-meter/quiz).
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
## 1. What does `on pin pressed(P0)` do?
|
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
It's a method that runs code when the user holds the GND pin with a finger of one hand and presses pin P0, completing a circuit.
|
|
|
|
|
|
|
|
## 2. Write the code.
|
|
|
|
|
|
|
|
Create a condition for `on pin pressed (P0)`.
|
|
|
|
|
2016-03-29 20:57:50 +02:00
|
|
|
```blocks
|
|
|
|
input.onPinPressed(TouchPin.P0, () => {
|
|
|
|
|
|
|
|
})
|
|
|
|
```
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
## 3. What does this line of code doing?
|
|
|
|
|
2016-03-29 22:13:18 +02:00
|
|
|
```blocks
|
|
|
|
let x = Math.random(9)
|
|
|
|
```
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
It stores random number between 0 and 9 then stores that number in a variable.
|
|
|
|
|
|
|
|
## 4. Why do you have to add 1 to variable x?
|
|
|
|
|
2016-03-29 22:13:18 +02:00
|
|
|
```blocks
|
|
|
|
let item = 0;
|
|
|
|
item = 0;
|
|
|
|
basic.showNumber(item + 1);
|
|
|
|
```
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
You have to add 1 if you want to generate a random number between 1 and 10 .
|
|
|
|
|
|
|
|
## 5. Why do you have to hold ground (GND) to make this work on the micro:bit?
|
|
|
|
|
|
|
|
|
|
|
|
You have told GND to complete the circuit.
|
|
|
|
|