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 = 0; i < 10; i++) { | AThe typed version of a repeat 10 block: the loop body runs 10 times. | |
| 2while (score !== 5) { | Blet score = 0; while (score !== 5) { score++; } | |
| 3A forever block with an if block inside becomes an endless while loop with an if statement in its body. | Cwhile (true) { if (touching) { console.log("Hit!"); } } | |
| 4A counter variable must be created before the loop so the loop condition can use it. | DThe typed version of a repeat until score = 5 block: keep looping while score is NOT 5. | |
| 5while (score === 5) { score++; } | EA forever block was typed as for with no loop that never ends; instead, the counter is used without being created. The variable count was never declared before it is used, so this causes a ReferenceError. | |
| 6for (let i = 0; i < 10; i++) { console.log(i); } console.log(count); | FThe condition was copied directly from repeat until score = 5. A while loop needs the opposite condition, score !== 5, so this loop never runs when score starts at 0. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
while (score !== 5) — Typed form of a repeat until score = 5 block: keep looping while the opposite is true. A repeat 10 block becomes a for loop, and forever becomes while (true).for (let i = 0; i < 10; i++) {
console.log("Hello");
}while (true) {
if (score > 5) { console.log("Win"); }
}let score = 0;
while (score !== 5) { score++; }let score = 0;
while (score !== 5) { score++; }for (let i = 0; i < 10; i++) {
console.log("Jump!");
}