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 | |
|---|---|---|
| 1if (age >= 13) { if (hasPermission) { console.log("Join"); } } | Aif (isLoggedIn && isAdmin) { console.log("Welcome"); } | |
| 2if (score > 50 && lives > 0) { | BThe inner if (hasPermission) is only checked when age >= 13 is true. It sits inside the outer braces and is indented again. | |
| 3Each if has its own braces, and the inner if is indented again inside the outer block | Cif (raining) { if (hasUmbrella) { console.log("Walk"); } } | |
| 4A nested if is the same as one if joined with && when there is no else | DThe inner if is missing its closing brace, so the braces do not match. Each if needs its own { and }. | |
| 5if (x > 0) { if (x < 10) { console.log("Small"); } | EOne if with a combined condition. Both parts must be true, and no inner if is needed. | |
| 6if (age >= 13) { if (hasPermission === true) { console.log("Join"); } } | FThe console.log line is not indented again inside the inner if. Its position makes it look like it belongs to the outer if. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if (a) { if (b) { } } — A nested if is an if inside another if's braces. The inner if is only checked when the outer condition is true. Each if has its own braces and the inner one is indented again.if (age >= 13) {
if (hasPass) { console.log("Enter"); }
}if (score >= 50) {
if (score >= 90) { console.log("Top"); }
}if (isRaining) {
if (hasUmbrella) { console.log("Go"); }
}if (age >= 13 && hasPass) {
console.log("Enter");
}if (loggedIn) {
if (role ===
"admin") { console.log("Hi"); }
}