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 <= 10; i++) { if (i % 2 === 0) { count++; } } | Afor (let i = 0; i < scores.length; i++) { if (scores[i] > 50) { passes++; } } | |
| 2for (let i = 1; i <= 5; i++) { if (i > 3) { console.log(i); } else { console.log("low"); } } | BPrints low for 1, 2 and 3, then prints the number for 4 and 5, because each pass takes a different branch. | |
| 3Count only the scores that are above 50 by putting an if inside the loop. | CChecks every number from 1 to 10 and adds 1 to count only when the number is even. | |
| 4Use % 2 inside a loop to tell whether each number is even. | DThe if uses = (assignment) instead of === (comparison), so it does not test whether i is even. It should be i % 2 === 0. | |
| 5for (let i = 1; i <= 10; i++) { if (i % 2 = 0) { count++; } } | Efor (let n = 1; n <= 8; n++) { if (n % 2 === 0) { console.log(n); } } | |
| 6if (i % 2 === 0) { for (let i = 1; i <= 10; i++) { count++; } } | FThe if is outside the loop, so it is only checked once and every number gets counted. The if must go inside the loop body. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for (...) { if (...) { ... } } — An if inside a loop body is checked again on every repeat, so each pass can take a different branch, such as counting only the matches.for (let n = 1; n <= 6; n++) {
if (n > 3) { console.log(n); }
}for (let i = 1; i <= 10; i++) {
if (i % 2 === 0) { console.log(i); }
}let count = 0;
for (let n = 1; n <= 9; n++) {
if (n > 5) { count++; } }for (let i = 1; i <= 4; i++) {
if (i > 2) { console.log("big"); }
else { console.log("small"); } }let total = 0;
for (let i = 1; i <= 10; i++) {
if (i % 2 === 0) { total += i; } }