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++) { for (let j = 1; j <= 4; j++) { | AInside a nested loop, this prints one multiplication result on every pass, using both counters to build a multiplication grid. | |
| 2console.log(i * j); | BThe inner loop reuses the counter name i from the outer loop, which makes the code confusing and error-prone. The inner loop should use a different counter name such as j. | |
| 3Building a row of stars: the inner loop adds a star to a string for each column, then the outer loop moves on to the next row. | CA nested loop: the inner j loop runs 4 times for each of the 3 runs of the outer i loop, giving 12 passes in total. | |
| 4An outer loop of 3 repeats with an inner loop of 4 repeats makes the inner loop body run 12 times in total. | Dlet count = 0; for (let i = 0; i < 3; i++) { for (let j = 0; j < 4; j++) { count++; } } console.log(count); | |
| 5for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 4; i++) { console.log(i); } } | Efor (let i = 0; i < 3; i++) { let row = ""; for (let j = 0; j < 4; j++) { row += "*"; } console.log(row); } | |
| 6for (let i = 1; i <= 3; i++) { for (let j = 1; j <= 4; j++) { console.log(i * j); } console.log("-"); } } | FThere is an extra closing brace at the end. Each loop needs exactly one matching closing brace, so a nested loop with two opening braces needs only two closing braces. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
nested loop — A loop inside another loop. The inner loop runs all its repeats for every single repeat of the outer loop, so an outer 3 and inner 4 gives 12 passes.for (let i = 1; i <= 3; i++) {
for (let j = 1; j <= 4; j++) count++;
}for (let i = 1; i <= 3; i++) {
for (let j = 1; j <= 4; j++) count++;
}for (let i = 1; i <= 3; i++) {
for (let j = 1; j <= 3; j++) t += i * j;
}for (let i = 1; i <= 3; i++) {
for (let j = 1; j <= 5; j++) row += "*";
}for (let i = 1; i <= 3; i++) {
for (let j = 1; j <= 4; j++) count++;
}