← ACARA Digital Technologies Years 7–8

Logic errors: runs but gives the wrong answer

A mistake that lets the program run with no error message but gives a wrong result, such as using > instead of >=, the wrong operator, or steps in the wrong order.

Understanding Logic errors: runs but gives the wrong answer in ACARA Digital Technologies Years 7–8

What it does: >= includes the value 50, whereas > would leave it out and give the wrong result. === checks whether the values are equal. A single = would overwrite answer and cause a logic error. A logic error lets the program run but gives a wrong result. A syntax error stops the program with an error message. age > 13 wrongly leaves out 13-year-olds. It should be age >= 13 so that 13 is included. With score > 50, a score of 50 does not pass. Using >= fixes the boundary value. The code runs, but + gives the wrong answer. The area needs the * operator.

Common mistakes: The program runs, but > leaves out a score of exactly 50, so a student who should pass is told nothing. It should be >= to include 50. Adding gives 23 instead of the cost of 3 items. The total needs multiplication: price * qty gives 60. There is no error message, just a wrong answer.

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
A program runs with no error message but prints the wrong total. What kind of mistake is this?
A logic errorA syntax error
Matches
if (guess = 7) {
↓
A single = assigns 7 to guess, so the condition is always true. There is no error message, but the answer is wrong. It should be ===.
Applying
Meanings
Term
logic error
Meaning
A mistake that lets the program run with no error message but gives a wrong result, such as using > instead of >=, the wrong operator, or steps in the wrong order.
Practice
let score = 50;
Testing
Gaps
if (score 50) console.log("Pass");
Check Answer
Spots
1let score = 50;
2if (score > 50) {

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

The 'Woodpecker' badge — Tap Tap Tap, 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. A program runs with no error message but prints the wrong total. What kind of mistake is this?
A. A logic error ✓
B. A syntax error
A logic error lets the program run but gives a wrong result. A syntax error stops the program with an error message.
2. Students must be 13 or older to join. Which condition has a logic error?
A. if (age > 13) ✓
B. if (age >= 13)
age > 13 wrongly leaves out 13-year-olds. It should be age >= 13 so that 13 is included.
3. A pass mark is 50 and a student scores exactly 50. Which line wrongly says they fail?
A. if (score > 50) { console.log("Pass"); } ✓
B. if (score >= 50) { console.log("Pass"); }
With score > 50, a score of 50 does not pass. Using >= fixes the boundary value.
4. You want the area of a rectangle: width times height. Which line has a logic error?
A. let area = width * height;
B. let area = width + height; ✓
The code runs, but + gives the wrong answer. The area needs the * operator.
5. This code should check if a password matches: if (password = "cats"). What is the problem?
A. It is fine, because = checks if two values are equal
B. It uses = (assignment) when it should use === (comparison) ✓
A single = assigns a value, so the condition is always truthy. Use === to compare.

Match the Pairs

if (age > 13) { → Runs with no error but leaves out a person who is exactly 13, which is a logic error if 13 should be allowed
let area = width + height; → Runs with no error but adds instead of multiplying, so the area is wrong. This is a wrong-operator logic error
Using >= so that a mark of exactly 50 counts as a pass fixes a boundary logic error → if (mark >= 50) {
Use === to compare two values, because a single = assigns a value instead of comparing → if (answer === 7) {
if (guess = 7) { → A single = assigns 7 to guess, so the condition is always true. There is no error message, but the answer is wrong. It should be ===.
let total = prompt("Number?") + 5; → prompt() gives back text, so + joins the text and 5 together ("35") instead of adding. The text should be converted with Number() first.

Key Term

logic error
A mistake that lets the program run with no error message but gives a wrong result, such as using > instead of >=, the wrong operator, or steps in the wrong order.

Fill in the Blanks

1. let score = 50; if (score >= 50) console.log("Pass");
Hint: Type the comparison operator that is also true when the score is exactly the pass mark.
2. let price = 8; let total = price * 3; console.log(total);
Hint: Type the arithmetic operator that finds the cost of 3 items, not the sum of price and 3.
3. let pin = 1234; if (pin === 1234) console.log("Open");
Hint: Type the operator that checks two values are equal, not the one that stores a value.
4. let age = prompt("Age?"); let next = Number(age) + 1; console.log(next);
Hint: Type the function that turns the typed text into a number so + adds instead of joining text.
5. let a = 80; let b = 90; let avg = (a + b) / 2;
Hint: Type the arithmetic operator that turns the total of two marks into their average.

Spot the Error

Question 1
A let score = 50;
B if (score > 50) {
C console.log("Pass");
D }
Line B — The program runs, but > leaves out a score of exactly 50, so a student who should pass is told nothing. It should be >= to include 50.
Question 2
A let price = 20;
B let qty = 3;
C let total = price + qty;
D console.log(total);
Line C — Adding gives 23 instead of the cost of 3 items. The total needs multiplication: price * qty gives 60. There is no error message, just a wrong answer.
Question 3
A let colour = "red";
B if (colour = "red") {
C console.log("Stop");
D }
Line B — A single = assigns a value instead of comparing, so the condition is always true. Use === to compare.
Question 4
A let a = 5;
B let b = 7;
C let c = 9;
D let sum = "" + a + b + c;
E console.log(sum);
Line D — Starting with an empty string makes + join the values as text, so the result is "579" instead of 21. It should be a + b + c.
Question 5
A let avg = 80 + 90 / 2;
B console.log("Average:", avg);
C console.log(avg >= 80);
Line A — Without brackets the division happens first, giving 125 instead of 85. Brackets are needed around the addition: (80 + 90) / 2.

Student with a class code? Join your class →