← ACARA Digital Technologies Years 7–8

else if chain versus separate if statements

In an else if chain, only the first true branch runs and the rest are skipped. Separate if statements are each checked, so more than one can run.

Understanding else if chain versus separate if statements in ACARA Digital Technologies Years 7–8

What it does: Each if is checked on its own, so a young member gets both discounts. The chain picks exactly one message because later branches are skipped after a match. Once one condition in the chain is true, JavaScript runs that branch and skips the rest of the chain. A chain guarantees only one grade is chosen. Separate ifs could give a mark more than one grade. The two checks are independent, so each needs its own if. A chain would skip the second check after the first was true. Fix it by making the second test a separate if so both conditions are checked and both can run.

Common mistakes: An else if must continue an existing if. Starting the chain with else if is a syntax error. The first test should be a plain if (temp > 30) {. Writing a plain if here makes it a separate check, so both big and mid go up when n is 8. The chain should use else if (n > 3) so that only the first true branch runs.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 583–598) and word search (Modules 583–613).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
In an if / else if / else chain, how many branches can run?
Every branch whose condition is trueAt most one branch
Matches
if (mark >= 90) { grade = 'A'; } if (mark >= 70) { grade = 'B'; } if (mark >= 50) { grade = 'C'; }
↓
Separate ifs are used where only one grade should apply. A mark of 95 passes all three tests, so grade ends up as 'C'.
Applying
Meanings
Term
else if
Meaning
In an else if chain, only the first true branch runs and the rest are skipped. Separate if statements are each checked, so more than one can run.
Practice
let mark = 85;
Testing
Gaps
if (age < 20) { console.log("Teen"); }
Check Answer
Spots
1let temp = 32;
2else if (temp > 30) {

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Warthog' badge — Definition Digger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. In an if / else if / else chain, how many branches can run?
A. At most one branch ✓
B. Every branch whose condition is true
Once one condition in the chain is true, JavaScript runs that branch and skips the rest of the chain.
2. let score = 85; Two separate statements: if (score > 50) { log('Pass') } and if (score > 80) { log('High') }. What is logged?
A. Only Pass
B. Pass and High ✓
Separate if statements are each checked on their own. Both conditions are true, so both blocks run.
3. let score = 85; if (score > 80) { log('High') } else if (score > 50) { log('Pass') }. What is logged?
A. Only High ✓
B. High and Pass
The first condition is true, so the chain stops there. The else if is never checked, even though score > 50 is also true.
4. Which code can run two blocks in a single pass?
A. Two separate if statements ✓
B. One if / else if chain
An else if chain runs at most one branch. Separate ifs are each checked, so more than one can run.
5. You want to give exactly one grade (A, B or C) for a mark. Which should you use?
A. Separate if statements
B. An if / else if chain ✓
A chain guarantees only one grade is chosen. Separate ifs could give a mark more than one grade.

Match the Pairs

if (score >= 50) { grade = 'Pass'; } if (score >= 80) { grade = 'High'; } → Two separate if statements: both are checked, so when score is 85 both run and grade ends up as 'High'.
if (score >= 80) { grade = 'High'; } else if (score >= 50) { grade = 'Pass'; } → An else if chain: it stops at the first true condition, so when score is 85 only 'High' runs and the second test is skipped.
Use separate if statements when more than one thing can be true at once, such as adding a bonus for each rule met. → if (age < 13) { cost -= 2; } if (isMember) { cost -= 1; }
Use an else if chain when only one outcome should happen, such as picking a single weather message. → if (temp > 30) { console.log('Hot'); } else if (temp > 20) { console.log('Warm'); } else { console.log('Cool'); }
if (mark >= 90) { grade = 'A'; } if (mark >= 70) { grade = 'B'; } if (mark >= 50) { grade = 'C'; } → Separate ifs are used where only one grade should apply. A mark of 95 passes all three tests, so grade ends up as 'C'.
if (isRaining) { bag = 'umbrella'; } else if (isSunny) { hat = 'cap'; } → An else if is used for two independent checks. If isRaining is true, isSunny is never checked, so the hat is skipped.

Key Term

else if
In an else if chain, only the first true branch runs and the rest are skipped. Separate if statements are each checked, so more than one can run.

Fill in the Blanks

1. if (age < 13) { console.log("Child"); } else if (age < 20) { console.log("Teen"); }
Hint: Type the keyword that links this check to the one above, so the second check is skipped when the first is true.
2. let score = 95; if (score >= 50) { console.log("Pass"); } if (score >= 90) { console.log("Top"); }
Hint: Type the keyword that starts a separate check, so it is tested even when the check above was true.
3. if (n > 0) { console.log("Positive"); } else if (n < 0) { console.log("Negative"); } else { console.log("Zero"); }
Hint: Type the keyword for the final catch-all branch that runs only when every earlier check in the chain was false.
4. let x = 7, count = 0; if (x > 0) { count++; } if (x > 5) { count++; }
Hint: Type the variable name that is increased when each separate if is true, so both ifs can add to the total.
5. if (mark >= 90) { console.log("A"); } else if (mark >= 70) { console.log("B"); } else { console.log("C"); }
Hint: Type the two keywords that add another check to the chain, which only runs if all the earlier checks were false.

Spot the Error

Question 1
A let temp = 32;
B else if (temp > 30) {
C console.log("Hot");
D } else if (temp > 20) {
E console.log("Warm");
F }
Line B — An else if must continue an existing if. Starting the chain with else if is a syntax error. The first test should be a plain if (temp > 30) {.
Question 2
A let n = 8, big = 0, mid = 0;
B if (n > 5) { big++; }
C if (n > 3) { mid++; }
D console.log(big, mid);
Line C — Writing a plain if here makes it a separate check, so both big and mid go up when n is 8. The chain should use else if (n > 3) so that only the first true branch runs.
Question 3
A let age = 15;
B if (age < 13) {
C console.log("Child");
D } else if age < 20 {
E console.log("Teen");
F }
Line D — The condition of an else if must be inside brackets, just like an if. It should be } else if (age < 20) {.
Question 4
A let n = -2, pos = 0, neg;
B if (n > 0) { pos++; }
C else if (n < 0) { neg++; }
D console.log(pos, neg);
Line A — neg is never given a starting value, so it is undefined and neg++ gives NaN. The counter must start at 0: neg = 0. Only the matching branch of the chain runs, so every counter needs a start value.
Question 5
A funtion level(n) {
B if (n >= 80) return 3;
C else if (n >= 50) return 2;
D return 1;
E }
Line A — The keyword is misspelled. A function that holds an else if chain must be declared with function, not funtion.

Student with a class code? Join your class →