else if Statements

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This else if Statements worksheet is part of the JavaScript Coding without HTML and CSS journey. Print it as a booklet?

else if Statements

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does else if check another condition when the first if was false?
A No
B Yes
2. Is 'elseif' with no space valid JavaScript syntax?
A No
B Yes
3. Can you chain multiple else if blocks together?
A Yes
B No
4. Does else if need its own condition in parentheses?
A No
B Yes
5. Will only one block in an if/else if chain run?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1} else if (score >= 70) { ... } AWrong - 'else if' needs a space between the words
2} else if (age < 18) { ... } BChecks this condition only if the earlier if was false
3Adds another condition to check after an if Cif / else if / else if
4Only one block in a chain of these runs DWrong - 'else' must be lowercase
5} elseif (score >= 70) { ... } Eelse if
6} Else if (age < 18) { ... } FRuns its block only if age < 18 and the first if was false

Definitions

else if

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
} _______ (score >= 70) {
2.
if (age < 13) { } else if (age < __) {
3.
if (n === 1) { } else if (n === _) {
4.
} else __ (temp > 30) {
5.
} ____ if (level === 2) {

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A } elseif (score >= 70) {
B if (score >= 90) {
C }
Question 2
A if (age < 13) {
B } Else if (age < 18) {
C }
Question 3
A if (n === 1) {
B }
C } else If (n === 2) {
Question 4
A if (temp > 30) {
B console.log("Hot");
C }
D } else if temp > 20) {
Question 5
A if (level === 1) {
B } else if (level === 2 {
C console.log("L1");
D }

Answer Key

else if Statements
Section A: Quick Questions
Q1
B — Yes
Q2
A — No
Q3
A — Yes
Q4
B — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
} else if (score >= 70) { ... } → Checks this condition only if the earlier if was false
Q2
} else if (age < 18) { ... } → Runs its block only if age < 18 and the first if was false
Q3
Adds another condition to check after an if → else if
Q4
Only one block in a chain of these runs → if / else if / else if
Q5
} elseif (score >= 70) { ... } → Wrong - 'else if' needs a space between the words
Q6
} Else if (age < 18) { ... } → Wrong - 'else' must be lowercase
Section C: Definitions
Q1
else if — Checks another condition only when the previous if or else if condition was false.
Section D: Fill in the Blanks
Q1
} else if (score >= 70) {
Q2
if (age < 13) { } else if (age < 18) {
Q3
if (n === 1) { } else if (n === 2) {
Q4
} else if (temp > 30) {
Q5
} else if (level === 2) {
Section E: Spot the Error
Q1
A — 'else if' needs a space - 'elseif' is not valid syntax.
Q2
B — 'else' must be lowercase - a capital E causes an error.
Q3
C — 'if' must be lowercase - a capital I causes an error.
Q4
D — The else if condition needs an opening parenthesis.
Q5
B — The else if condition is missing a closing parenthesis.