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 = 1; i <= 3; i++) { console.log(i); } | Afor (let i = 1; i <= 3; i++) { } console.log(i); | |
| 2for (let i = 1; i <= 5; i++) { console.log(i * 7); } | Bi is in quotes, so the text i is printed five times instead of the counter values 1 to 5. Remove the quotes: console.log(i). | |
| 3Starting the counter at 0 means the first value used in the loop body is 0 | CPrints the 7 times table: 7, 14, 21, 28, 35 | |
| 4The counter i is local to the loop, so using it after the loop causes a ReferenceError | DThe loop body never uses i, so it prints 7 every time. It should be console.log(i * 7) to get a different answer each repeat. | |
| 5for (let i = 1; i <= 5; i++) { console.log("i"); } | EPrints 1, then 2, then 3, because the counter i changes on every repeat | |
| 6for (let i = 1; i <= 5; i++) { console.log(7); } | Ffor (let i = 0; i < 3; i++) { console.log(i); } |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
console.log(i) — Inside a for loop, the counter i changes on every repeat, so using it in the loop body gives a different value each time, like 1, 2, 3. It only exists inside the loop.for (let i = 1; i <= 5; i++) {
console.log(i);
}for (let i = 1; i <= 12; i++) {
console.log(i * 7);
}for (let i = 0; i < 3; i++) {
console.log(i);
}for (let i = 1; i <= 3; i++) {
console.log(i);
}for (let i = 1; i <= 12; i++) {
console.log(`${i} x 7 = ${i * 7}`);
}