Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1console.log(total); // ReferenceError: total is not defined | ADeclaring score twice with let causes a syntax error. Fix this one line (score = score + 5;) and then rerun. | |
| 2console.log(add(2, 3)); // shows 6, expected 5 | Bfunction double(n) { return n + 2; } // fix to n * 2 console.log(double(5)); // retest: expect 10 | |
| 3Fix syntax errors first, because a missing bracket stops the program running at all, and then look for logic errors. | CThe error message names the problem and the line number, so you read it first, find that line, fix one thing and rerun. | |
| 4Check whether the bug is inside a function or in the main program, then fix one thing and retest by calling the function again. | Dconsole.log("Hi"; // fix to: console.log("Hi"); | |
| 5let score = 10; let score = score + 5; | EA logic error: the program runs but the output does not match what you expected, so you check the function's code and fix it. | |
| 6function average(a, b) { return a + b / 2; } | FA 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. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
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.let total = 0;
console.log("total is", total);function area(w, h) {
return w * h;
}function double(n) { return n * 2; }
console.log(double(4)); // expected 8let score = 10;
if (score === 10) console.log("Full marks");function add(a, b) {
return a + b;
}