Debugging with console.log()
Prints a labelled variable value while the program runs, so you can spot the line where the value first goes wrong. Remove these debug lines once the bug is fixed.
Understanding Debugging with console.log() in ACARA Digital Technologies Years 7–8
What it does: A console.log inside the loop body runs on every repeat, so you see each value of i and can spot where it first goes wrong. Commenting out (or deleting) the debug line stops it printing. The program still works and the console only shows the real output. A label tells you which variable the number belongs to, which matters when you print several values. Logging the parameters shows what the function actually received. You can also log the result before returning it. The label and the variable are separated by a comma inside the brackets. console.log only displays a value. It does not change the variable, which makes it safe for checking your code.
Common mistakes: total is already declared on line 1, so let cannot declare it again. Line 2 should reassign it with total = total + 5; so the console.log on line 3 can show the new value. =+ sets sum to positive i instead of adding to it. The logged sum would show 1, 2, 3, not 1, 3, 6. It should be sum += i; and the log inside the loop is how you spot where the value goes wrong.
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 624–634) and word search (Modules 611–634).
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.log("total:", total)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →