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 | |
|---|---|---|
| 1for (let i = 10; i >= 1; i--) | Afor (let i = 10; i >= 1; i--) | |
| 2for (let i = 10; i >= 0; i -= 2) | Bfor (let i = 10; i >= 1; i--) { console.log(i); } | |
| 3To count down, the loop condition must use >= so the loop keeps running while the counter is still at or above the last number | CCounts down from 10 to 1, taking away 1 each time the loop repeats | |
| 4A countdown loop updates the counter by subtracting, so the counter gets smaller every time | DThe condition i <= 1 is false straight away because 10 is not less than or equal to 1, so the loop never runs. It should be i >= 1. | |
| 5for (let i = 10; i >= 1; i++) | EThe update i++ adds 1, so the counter goes up away from 1 and the loop never ends. It should be i--. | |
| 6for (let i = 10; i <= 1; i--) | FCounts down from 10 to 0 in steps of 2: 10, 8, 6, 4, 2, 0 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for (let i = 10; i >= 1; i--) — A for loop that counts down: start i high, keep going while i >= 1, and subtract 1 each time with i--. Use i -= 2 to count down in steps of 2.for (let i = 10; i >= 1; i--) {
console.log(i);
}for (let i = 10; i >= 1; i--) {
console.log(i);
}for (let i = 10; i >= 1; i--) {
console.log(i);
}for (let i = 10; i >= 1; i -= 2) {
console.log(i);
}for (let i = 10; i >= 1; i--) {
console.log(i);
}