1.5 KiB
1.5 KiB
counter quiz answers
Learn how to create a counter with the BBC micro:bit button.
This is the answer key for the 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
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.
3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
We are only pressing on button pressed once. So the number to display on the micro:bit is also one.
4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
let count = 0
input.onButtonPressed(Button.A, () => {
count = + 1
basic.showNumber(count)
})
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