pxt-calliope/docs/lessons/counter/quiz-answers.md
Michael Elliot Braun 1e77491b16 updated lessons
2016-03-30 15:11:05 -07:00

55 lines
1.5 KiB
Markdown

# counter quiz answers
Learn how to create a counter with the BBC micro:bit button.
This is the answer key for the [counter quiz](/microbit/lessons/counter/quiz).
## 1. What is a variable?
Answers may vary but a variable is a place where you can store and retrieve data
## 2. Draw the stored value for the variable called count
```blocks
let count = 0
```
![](/static/mb/lessons/counter-0.png)
We create a **variable**, `count` to keep track of the current count. The number 0 is stored into memory of the variable.
<br/>
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
```blocks
let counts = 0
input.onButtonPressed(Button.A, () => {
counts = counts + 1
basic.showNumber(counts, 150)
})
```
![](/static/mb/lessons/counter-1.png)
We are only pressing on button pressed once. So the number to display on the micro:bit is also one.
<br/>
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
```blocks
let counting= 0
input.onButtonPressed(Button.A, () => {
counting = counting + 1
basic.showNumber(counting, 100)
})
```
![](/static/mb/lessons/counter-2.png)
We included the code ``on button pressed("A")`` that runs each time the user presses A. The code increments `count` by `1`. We increase `count` by 1 whenever the user presses the button. So the third time the A button is pressed on the BBC micro:bit, the number 3 is displayed
<br/>