Higher or lower number guessing game
The heart of a guessing game: keep asking for guesses until the guess equals the random secret number, using if/else if for too high or too low and a counter for the number of guesses.
Understanding Higher or lower number guessing game in ACARA Digital Technologies Years 7–8
What it does: Using > compares the guess with the secret. If the guess is bigger, the game prints a too high message. The ++ shorthand adds 1 to the guesses variable each time the loop runs, so it stores how many guesses the player has made. Math.random() gives a decimal from 0 up to (but not including) 1. Multiply by 10, use Math.floor() to round down, then add 1 to get 1 to 10. No guesses have been made yet, so the counter starts at 0. It is not related to the secret number. prompt() gives back text. Wrap it in Number() so you can compare it with the secret number.
Common mistakes: JavaScript is case sensitive. The method is Math.floor with a lowercase f, so Math.Floor causes an error. The line should be let secret = Math.floor(r)+1;. A single = assigns a value instead of comparing. The loop must keep going while the guess is NOT equal to the secret, so use while (guess !== secret) {.
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 635–666) and word search (Modules 635–695).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
while (guess !== secret)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →