CodeTeachersExplore programs

A free project for families & classrooms

Build something small.
Explain something real.

A tiny collecting game has a sneaky bug. Predict what will happen, change one rule, then prove that your fix works. Finish with a reflection sheet you can print or save.

This is a sample learning activity, not a confirmed class curriculum or a promise of a future session. An adult can adjust the pace and reading support.

01 / Predict & test

The mission: collect at least five stars.

A normal star gives one point. A bonus star gives two. The starter rule says the game is won only when the score is exactly five.

score = score + points;
won = score === 5;

Predict: you have four points, then collect a two-point bonus. Does the starter rule declare a win? Does that match the mission?

  1. Choose “Exactly five” in the demo.
  2. Set the score to four, then collect a bonus.
  3. Compare what happened with your prediction.

No JavaScript experience needed: === means “is exactly equal to.”

Your testing space

The star collector

Current score0

Keep collecting. The rule does not declare a win.

02 / Change one thing

Make the rule match the mission.

Choose “At least five” in the demo. This changes one comparison:

won = score >= 5;

>= means “greater than or equal to.” Retest four points plus a bonus. Then test all three cases below. A good fix works on the surprising case and keeps the ordinary cases working.

Test each score against the mission: collect at least five stars.
TestExpected resultHow to try it
Score is 4Keep collectingSet score to 4
Score is 5WinSet score to 4, add 1
Score is 6WinSet score to 4, add 2

Paper version: draw six stars and use a token to mark the score. Compare each test with “exactly five” and “at least five.” You can explain the bug and complete the reflection without a screen.

03 / Explain your own thinking

Build, test, explain: my reflection

CodeTeachers · Star collector sample · No name is needed. Keep personal information out of your notes.

Make one decision yourself.

Choose a new target, such as seven stars. On paper, write the winning rule and three tests: one score below your target, exactly the target, and above it. Explain how a bonus might skip over the target.

A useful finished project

For the adult: ask “What did you expect?” before giving a fix. Let the learner point to a test as evidence. If an adult chooses to use an AI tool, ask it for a hint or explanation, then let the learner make and test the change. This activity itself uses no AI service.

Download activity (.html)

Notes stay only in this tab and disappear when you reload or close it. Print or save your notes first. This standalone activity makes no background network requests and uses no analytics, cookies or browser storage.

Adult answer guide

With the starter rule, a score of six does not equal five, so the game fails to declare a win even though the mission is complete. The corrected rule accepts five and any larger score. Four stays a loss; five and six both win. For a target of seven, useful tests are six (not yet), seven (win), and eight (win).

Listen for the reason, not just the symbol. “I changed it because the goal says at least five” shows the learner has connected the code to the intended behavior.