← ACARA Digital Technologies Years 5–6

Number guessing game algorithm

The guessing game loop: keep asking for a guess until it matches the secret number. Inside, decide too high, too low or correct, and add 1 to the count each time.

Understanding Number guessing game algorithm in ACARA Digital Technologies Years 5–6

What it does: This step makes the counter go up by 1 for each guess, so the game can tell the player how many tries it took. 70 is bigger than 50, so the guess is too high. The player should try a smaller number. To say too low, the algorithm must check guess < secret. The wrong version checks > twice, so 'too low' could never happen. No guesses have been made yet, so count starts at 0. It is not related to the secret number. Every guess is counted, including the winning one. Guesses 3, 9 and 7 make 3 guesses.

Common mistakes: The count must start at 0 because no guesses have been made yet. Starting at 1 makes the total one too many. It should be SET count TO 0. The player types a guess, not the secret number. Typing into secret would change the number being guessed. It should be INPUT guess.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 120–132) and word search (Modules 106–132).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which loop line keeps a number guessing game going until the player wins?
REPEAT UNTIL guess = secretREPEAT 1 TIME
Matches
REPEAT UNTIL guess > secret
↓
The loop stops when the guess is too high, not when it is correct. It should be REPEAT UNTIL guess = secret.
Applying
Meanings
Term
REPEAT UNTIL guess = secret
Meaning
The guessing game loop: keep asking for a guess until it matches the secret number. Inside, decide too high, too low or correct, and add 1 to the count each time.
Practice
SET secret TO 7
Testing
Gaps
SET count ←
Check Answer
Spots
1SET count TO 1
2REPEAT UNTIL guess = secret

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Constellation Wolf' badge — Space Legend, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which loop line keeps a number guessing game going until the player wins?
A. REPEAT 1 TIME
B. REPEAT UNTIL guess = secret ✓
The game must repeat until the guess matches the secret number. We don't know how many guesses it will take, so a set number of repeats won't work.
2. The secret number is 50 and the player guesses 70. What should the algorithm say?
A. Too low
B. Too high ✓
70 is bigger than 50, so the guess is too high. The player should try a smaller number.
3. The secret number is 32 and the player guesses 18. What should the algorithm say?
A. Too low ✓
B. Too high
18 is smaller than 32, so the guess is too low. The player should try a bigger number.
4. Which set of decisions covers every possible guess?
A. IF guess > secret THEN too high, ELSE IF guess < secret THEN too low, ELSE correct ✓
B. IF guess > secret THEN too high, ELSE IF guess > secret THEN too low, ELSE correct
To say too low, the algorithm must check guess < secret. The wrong version checks > twice, so 'too low' could never happen.
5. Where should 'add 1 to count' go to count every guess?
A. Inside the loop, once for each guess ✓
B. After the loop, just once
The count must go up each time the player guesses, so the step belongs inside the loop. Putting it after the loop would only add 1 at the very end.

Match the Pairs

REPEAT UNTIL guess = secret → Keep asking for guesses again and again until the guess matches the secret number.
IF guess > secret THEN SAY "Too high" → If the guess is bigger than the secret number, tell the player the guess is too high.
Count every guess by adding 1 to the counter each time round the loop. → count ← count + 1
The decision for a wrong guess that is smaller than the secret number gives a 'too low' clue. → IF guess < secret THEN SAY "Too low"
REPEAT UNTIL guess > secret → The loop stops when the guess is too high, not when it is correct. It should be REPEAT UNTIL guess = secret.
SET count ← 0 (placed inside the loop) → The counter is reset to 0 on every go round the loop, so it never counts above 1. Set count to 0 once before the loop starts.

Key Term

REPEAT UNTIL guess = secret
The guessing game loop: keep asking for a guess until it matches the secret number. Inside, decide too high, too low or correct, and add 1 to the count each time.

Fill in the Blanks

1. SET secret ← 7 SET count ← 0 REPEAT UNTIL guess = secret
Hint: Type the number the guess counter starts at before any guesses are made.
2. REPEAT UNTIL guess = secret INPUT guess SET count ← count + 1
Hint: Type the keyword that keeps the loop going until the condition becomes true.
3. IF guess < secret THEN OUTPUT "Too low"
Hint: Type the comparison symbol that checks if the guess is smaller than the secret number.
4. INPUT guess SET count ← count + 1
Hint: Type the operator that adds one to the counter after each guess.
5. IF guess = secret THEN OUTPUT "Correct! Guesses: ", count
Hint: Type the name of the variable that holds how many guesses the player has made.

Spot the Error

Question 1
A SET count TO 1
B REPEAT UNTIL guess = secret
C INPUT guess
D ADD 1 TO count
Line A — The count must start at 0 because no guesses have been made yet. Starting at 1 makes the total one too many. It should be SET count TO 0.
Question 2
A SET secret TO 7
B SET count TO 0
C REPEAT UNTIL guess = secret
D INPUT secret
E ADD 1 TO count
Line D — The player types a guess, not the secret number. Typing into secret would change the number being guessed. It should be INPUT guess.
Question 3
A SET count TO 0
B REPEAT UNTIL guess ≠ secret
C INPUT guess
D ADD 1 TO count
Line B — The game must keep going until the guess is the same as the secret. With ≠ the loop would stop on a wrong guess. It should be REPEAT UNTIL guess = secret.
Question 4
A INPUT guess
B IF guess < secret THEN
C OUTPUT "Too high"
D ENDIF
Line B — The message says Too high, so the condition must check for a guess bigger than the secret. It should be IF guess > secret THEN.
Question 5
A REPEAT UNTIL guess = secret
B INPUT guess
C IF guess < secret
D OUTPUT "Too low"
E ADD 1 TO count
Line C — An IF decision needs the word THEN after the condition. It should be IF guess < secret THEN.

Student with a class code? Join your class →