Testing a function with console.assert
Prints the message only when the condition is false, so a test like console.assert(add(2, 3) === 5) stays silent when the function gives the expected result.
Understanding Testing a function with console.assert in ACARA Digital Technologies Years 9–10
What it does: Each console.assert line is a separate test case. Only the ones that fail will print their message, so you can see which input broke. square(3) is the actual result produced by the function, and 9 is the expected result. The === checks that they are equal. The condition must be a comparison like add(2, 3) === 5. Using = is a syntax error and does not test anything.
Common mistakes: A single = assigns a value instead of comparing, so this is not a real test (and 9 can't be assigned to a function call). The condition must use === like this: console.assert(sq(3) === 9);. The method name is misspelled. It must be console.assert with two s letters, otherwise JavaScript throws an error and the test never runs.
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 710–727) and word search (Modules 710–742).
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
console.assert(condition, message)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →