2016-03-25 16:47:20 -07:00
# 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
2016-03-29 16:17:34 -07:00
```blocks
2016-03-25 16:47:20 -07:00
let count = 0
```

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
2016-03-29 16:17:34 -07:00
```blocks
2016-03-25 16:47:20 -07:00
let count_ = 0
2016-03-29 21:17:57 -07:00
input.onButtonPressed(Button.A, () => {
2016-03-25 16:47:20 -07:00
count_ = count_ + 1
basic.showNumber(count, 150)
})
```

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
2016-03-29 16:17:34 -07:00
```blocks
2016-03-25 16:47:20 -07:00
count_ = 0
2016-03-29 21:17:57 -07:00
input.onButtonPressed(Button.A, () => {
2016-03-25 16:47:20 -07:00
count_ = count_ + 1
basic.showNumber(count_, 100)
})
```

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 / >