Students build a reaction game from an almost empty starter in three milestones, using a random wait, running time, a true/false variable, decisions and a best score.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict, Run, Investigate 12 min · Milestone 1 12 min · Milestone 2 12 min · Milestone 3 14 min · Why random 5 min
This challenge adds nothing new: every part was taught earlier in the course. Time between gave the timing (store running time in start, then running time − start); True or false gave waiting, the flag that catches early presses. The milestones fade the help: Milestone 1 lists the steps, Milestone 2 gives only the goal, Milestone 3 only goals. Play it yourself first; good times are 200 to 400 ms, and the simulator adds a little delay.
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
One student presses B on the projector; the class claps when they think the heart will come.
Nobody can time it. That is the point of the random wait.
On the board, list the game's jobs. Next to each, write the event that does it: B or A.
This list is the plan for Milestones 1 and 2.
Write your best time on the board. Who is fastest in the class?
Putting the parts in the right events. Ask which event each job belongs in: B or A.
| What you will see | A question to ask | The fix |
|---|---|---|
| The time shown is huge, like 15000. | When is start set? | Set start to running time straight after the heart is shown. |
| Every press shows a cross. | Where is waiting set to true? | Set waiting to true after the heart appears (after start is set). |
| The best time never changes, or is always the latest time. | What is best at the start, and which way round is your comparison? | Start best at 99999, and use if reaction < best. |
One possible solution for each task. Other correct programs are fine.

let start = 0
input.onButtonPressed(Button.B, function () {
basic.clearScreen()
basic.pause(randint(1000, 4000))
basic.showIcon(IconNames.Heart)
start = input.runningTime()
})
input.onButtonPressed(Button.A, function () {
basic.showNumber(input.runningTime() - start)
})

let waiting = false
let start = 0
input.onButtonPressed(Button.B, function () {
waiting = false
basic.clearScreen()
basic.pause(randint(1000, 4000))
basic.showIcon(IconNames.Heart)
start = input.runningTime()
waiting = true
})
input.onButtonPressed(Button.A, function () {
if (waiting) {
waiting = false
basic.showNumber(input.runningTime() - start)
} else {
basic.showIcon(IconNames.No)
}
})

let reaction = 0
let waiting = false
let start = 0
let best = 99999
input.onButtonPressed(Button.B, function () {
waiting = false
basic.clearScreen()
basic.pause(randint(1000, 4000))
basic.showIcon(IconNames.Heart)
start = input.runningTime()
waiting = true
})
input.onButtonPressed(Button.A, function () {
if (waiting) {
waiting = false
reaction = input.runningTime() - start
basic.showNumber(reaction)
if (reaction < best) {
best = reaction
basic.showIcon(IconNames.Happy)
}
} else {
basic.showIcon(IconNames.No)
}
})
input.onButtonPressed(Button.AB, function () {
basic.showString("Best")
basic.showNumber(best)
})
Open task: any program that does what the step asks.
Stretch: Show a rating after each time: under 250 a happy face, under 400 a meh face, otherwise a sad face (if, else if, else).
Support: Give students last lesson's no-cheating program as their Milestone 1 starter, and focus on Milestone 3.
Why does the game need waiting? What would happen without it?
Without it, pressing A before the heart still shows a number, so players could cheat by pressing early.
Next: Radio duel, the same game for two players over radio. Class ideas: a class reaction leaderboard on the board; does reaction time change after exercise? (a quick science investigation with real micro:bits).