← ACARA Digital Technologies Years 7–8

Finding and fixing bugs in a program

Finding and fixing bugs: run the program, read the error or compare wrong output with what you expected, find the faulty line, fix one thing, then rerun to retest.

Understanding Finding and fixing bugs in a program in ACARA Digital Technologies Years 7–8

What it does: The missing closing bracket is a syntax error. It must be fixed before the program can run and logic errors can be found. The bug is inside the function (n + 2 should be n * 2). After fixing one thing, rerunning the call tests whether the fix worked. Error messages tell you what went wrong and usually which line. Reading them is the first step in debugging. Logic errors run without crashing but give the wrong answer. You find them by comparing the actual output with the expected output. No error does not mean no bugs. Retest to check the output is what you expected.

Common mistakes: Syntax error: the bracket is never closed. Fix syntax errors first. The line should be console.log(score);. Syntax error: the keyword is misspelled. JavaScript reads 'function' only when spelled exactly. Fix it, then rerun.

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 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.

Learning
Duo
Your program crashes with an error message. What should you do first?
Read the error message and find the line it points toDelete the whole program and start again
Matches
let score = 10; let score = score + 5;
↓
Declaring score twice with let causes a syntax error. Fix this one line (score = score + 5;) and then rerun.
Applying
Meanings
Term
debugging
Meaning
Finding and fixing bugs: run the program, read the error or compare wrong output with what you expected, find the faulty line, fix one thing, then rerun to retest.
Practice
// Bug fixed: added brackets around a + b
Testing
Gaps
("total is", total);
Check Answer
Spots
1let score = 10;
2console.log(score;

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

The 'Pufferfish' badge — Error Handler, 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. Your program crashes with an error message. What should you do first?
A. Read the error message and find the line it points to ✓
B. Delete the whole program and start again
Error messages tell you what went wrong and usually which line. Reading them is the first step in debugging.
2. Which is the better way to fix a program with three bugs?
A. Fix one bug, then rerun the program to retest ✓
B. Change all three lines at once, then run it
Fixing one thing at a time means you know which change worked. Rerun after every fix.
3. Your program has a missing bracket (syntax error) and also adds when it should subtract (logic error). Which do you fix first?
A. The logic error, because it is harder
B. The syntax error, because the program cannot run until it is fixed ✓
Syntax errors stop the program from running at all, so fix them first. Then you can see the logic errors in the output.
4. A program runs with no error message but shows 15 when you expected 50. What kind of bug is this?
A. A syntax error: the computer would have shown a message
B. A logic error: compare the output with what you expected ✓
Logic errors run without crashing but give the wrong answer. You find them by comparing the actual output with the expected output.
5. You fixed a bug and the error message disappeared. What should you do next?
A. Run the program again and check the output is correct ✓
B. Assume it works and stop testing
No error does not mean no bugs. Retest to check the output is what you expected.

Match the Pairs

console.log(total); // ReferenceError: total is not defined → The error message names the problem and the line number, so you read it first, find that line, fix one thing and rerun.
console.log(add(2, 3)); // shows 6, expected 5 → A logic error: the program runs but the output does not match what you expected, so you check the function's code and fix it.
Fix syntax errors first, because a missing bracket stops the program running at all, and then look for logic errors. → console.log("Hi"; // fix to: console.log("Hi");
Check whether the bug is inside a function or in the main program, then fix one thing and retest by calling the function again. → function double(n) { return n + 2; } // fix to n * 2 console.log(double(5)); // retest: expect 10
let score = 10; let score = score + 5; → Declaring score twice with let causes a syntax error. Fix this one line (score = score + 5;) and then rerun.
function average(a, b) { return a + b / 2; } → A logic error: it runs but gives wrong answers because of the order of operations. Fix it to (a + b) / 2, then retest with known values.

Key Term

debugging
Finding and fixing bugs: run the program, read the error or compare wrong output with what you expected, find the faulty line, fix one thing, then rerun to retest.

Fill in the Blanks

1. let total = 0; console.log("total is", total);
Hint: Type the function that prints a value to the console so you can check it while debugging.
2. function area(w, h) { return w * h; }
Hint: Type the arithmetic operator that fixes this logic error, so the area is calculated correctly.
3. function double(n) { return n * 2; } console.log(double(4)); // expected 8
Hint: Type the name of the function you are retesting after the fix.
4. let score = 10; if (score === 10) console.log("Full marks");
Hint: Type the operator that compares two values, fixing a bug where a single assignment symbol was used.
5. function add(a, b) { return a + b; }
Hint: Type the keyword that sends the answer from the function back to the main program, so the call no longer gives undefined.

Spot the Error

Question 1
A let score = 10;
B console.log(score;
C score = score + 5;
D console.log(score);
Line B — Syntax error: the bracket is never closed. Fix syntax errors first. The line should be console.log(score);
Question 2
A fuction double(n) {
B return n * 2;
C }
D console.log(double(4));
Line A — Syntax error: the keyword is misspelled. JavaScript reads 'function' only when spelled exactly. Fix it, then rerun.
Question 3
A let price = 20;
B let qty = 3;
C // expected total: 60
D let total = price + qty;
E console.log(total);
Line D — Logic error: the program runs but prints 23 instead of the expected 60. The total should be price * qty.
Question 4
A let count = 1;
B for (let i = 0; i < 5; i++) {
C count++;
D }
E console.log(count);
Line A — Logic error: the counter starts at 1, so the loop prints 6 instead of the expected 5. It should start at 0.
Question 5
A function greet(name) {
B return 'Hi ' + name;
C }
D let msg = Greet('Sam');
E console.log(msg);
Line D — The bug is in the main program, not the function. JavaScript is case sensitive, so Greet is not defined (ReferenceError). Use greet.

Student with a class code? Join your class →