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 | |
|---|---|---|
| 1let total = 0; | Alet total = 0 is inside the loop, so the total is reset to 0 on every pass and never builds up. It must be set before the loop. | |
| 2count++; | Bcount = 1 sets the counter to 1 every time instead of adding 1, so it never goes above 1. It should be count++. | |
| 3Add each value in the loop to the running total | Cconsole.log(total); | |
| 4Show the final total once, after the loop has finished | DSets the running total to 0 before the loop starts, so every value can be added onto a clean start. | |
| 5for (let i = 1; i <= 5; i++) { let total = 0; total += i; } | Etotal += i; | |
| 6let count = 0; for (let i = 1; i <= 5; i++) { count = 1; } | FAdds 1 to the counter each time it runs, so it counts how many times something happened. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
total += value; — Adds each value to a running total inside a loop. Start with let total = 0 before the loop, and use count++ to count how many times something happens. Print the results after the loop.let total = 0;
for (let i = 1; i <= 5; i++) total += i;
console.log(total);let total = 0;
for (let i = 1; i <= 5; i++) total += i;
console.log(total);let count = 0;
for (let i = 0; i < 5; i++) count++;
console.log(count);let total = 0;
for (let i = 1; i <= 4; i++) total += i;
console.log(total);let total = 0;
for (let i = 1; i <= 3; i++) total += i * 2;
console.log(total);