Bird
Raised Fist0
Javascriptprogramming~20 mins

Else–if ladder in Javascript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Else-if Ladder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of else-if ladder with numeric input
What is the output of this JavaScript code?
let score = 75;
if (score >= 90) {
  console.log('Grade A');
} else if (score >= 80) {
  console.log('Grade B');
} else if (score >= 70) {
  console.log('Grade C');
} else {
  console.log('Grade F');
}
Javascript
let score = 75;
if (score >= 90) {
  console.log('Grade A');
} else if (score >= 80) {
  console.log('Grade B');
} else if (score >= 70) {
  console.log('Grade C');
} else {
  console.log('Grade F');
}
AGrade F
BGrade B
CGrade A
DGrade C
Attempts:
2 left
💡 Hint
Check which condition matches the score 75 first.
❓ Predict Output
intermediate
2:00remaining
Output when all conditions fail in else-if ladder
What will this code print?
let temperature = 10;
if (temperature > 30) {
  console.log('Hot');
} else if (temperature > 20) {
  console.log('Warm');
} else if (temperature > 15) {
  console.log('Mild');
} else {
  console.log('Cold');
}
Javascript
let temperature = 10;
if (temperature > 30) {
  console.log('Hot');
} else if (temperature > 20) {
  console.log('Warm');
} else if (temperature > 15) {
  console.log('Mild');
} else {
  console.log('Cold');
}
AMild
BCold
CWarm
DHot
Attempts:
2 left
💡 Hint
Check if 10 is greater than any of the conditions.
❓ Predict Output
advanced
2:00remaining
Output of else-if ladder with string comparison
What does this code print?
let day = 'Sunday';
if (day === 'Monday') {
  console.log('Start of work week');
} else if (day === 'Friday') {
  console.log('End of work week');
} else if (day === 'Saturday' || day === 'Sunday') {
  console.log('Weekend');
} else {
  console.log('Midweek');
}
Javascript
let day = 'Sunday';
if (day === 'Monday') {
  console.log('Start of work week');
} else if (day === 'Friday') {
  console.log('End of work week');
} else if (day === 'Saturday' || day === 'Sunday') {
  console.log('Weekend');
} else {
  console.log('Midweek');
}
AStart of work week
BMidweek
CWeekend
DEnd of work week
Attempts:
2 left
💡 Hint
Check the condition that matches 'Sunday'.
❓ Predict Output
advanced
2:00remaining
Output when else-if ladder conditions overlap
What will this code print?
let num = 5;
if (num > 0) {
  console.log('Positive');
} else if (num > 3) {
  console.log('Greater than three');
} else {
  console.log('Other');
}
Javascript
let num = 5;
if (num > 0) {
  console.log('Positive');
} else if (num > 3) {
  console.log('Greater than three');
} else {
  console.log('Other');
}
APositive
BGreater than three
COther
DNo output
Attempts:
2 left
💡 Hint
Remember else-if ladder stops at first true condition.
❓ Predict Output
expert
2:00remaining
Output of else-if ladder with nested conditions and variable changes
What is the output of this code?
let x = 10;
if (x > 5) {
  if (x < 15) {
    x += 5;
  } else if (x === 15) {
    x += 10;
  }
} else if (x === 10) {
  x -= 5;
}
console.log(x);
Javascript
let x = 10;
if (x > 5) {
  if (x < 15) {
    x += 5;
  } else if (x === 15) {
    x += 10;
  }
} else if (x === 10) {
  x -= 5;
}
console.log(x);
A15
B20
C5
D10
Attempts:
2 left
💡 Hint
Trace the nested if conditions carefully.

Practice

(1/5)
1. What does an else if ladder do in JavaScript?
easy
A. Only runs the last condition regardless of others
B. Runs all true conditions in sequence
C. Checks multiple conditions one by one and runs the first true block
D. Skips all conditions and runs default code

Solution

  1. Step 1: Understand else if ladder behavior

    An else if ladder checks conditions in order, one after another.
  2. Step 2: Identify which block runs

    Only the first condition that is true will run its code block; others are skipped.
  3. Final Answer:

    Checks multiple conditions one by one and runs the first true block -> Option C
  4. Quick Check:

    else if ladder = first true block runs [OK]
Hint: Remember: else if stops at first true condition [OK]
Common Mistakes:
  • Thinking all true blocks run
  • Confusing else if with separate if statements
  • Believing else if runs last condition only
2. Which of the following is the correct syntax for an else if ladder in JavaScript?
easy
A. if (x > 10) {} else if (x > 5) {} else {}
B. if x > 10 then {} else if x > 5 then {} else {}
C. if (x > 10) {} elseif (x > 5) {} else {}
D. if (x > 10) {} else (x > 5) {} else {}

Solution

  1. Step 1: Check JavaScript syntax rules

    JavaScript uses parentheses around conditions and keywords: if, else if, else.
  2. Step 2: Identify correct else if syntax

    The correct keyword is else if with a space, not elseif or missing parentheses.
  3. Final Answer:

    if (x > 10) {} else if (x > 5) {} else {} -> Option A
  4. Quick Check:

    Correct else if syntax = if (x > 10) {} else if (x > 5) {} else {} [OK]
Hint: Use 'else if' with space and parentheses [OK]
Common Mistakes:
  • Writing 'elseif' as one word
  • Omitting parentheses around conditions
  • Using else with a condition directly
3. What will be the output of this code?
let score = 75;
if (score >= 90) {
  console.log('A');
} else if (score >= 80) {
  console.log('B');
} else if (score >= 70) {
  console.log('C');
} else {
  console.log('F');
}
medium
A. A
B. C
C. B
D. F

Solution

  1. Step 1: Check conditions in order

    score is 75, so first condition (>=90) is false, second (>=80) is false, third (>=70) is true.
  2. Step 2: Identify which block runs

    The third else if block runs and prints 'C'. The else block is skipped.
  3. Final Answer:

    C -> Option B
  4. Quick Check:

    First true condition output = C [OK]
Hint: Check conditions top to bottom, first true runs [OK]
Common Mistakes:
  • Picking output 'B' or 'A' incorrectly
  • Ignoring order of conditions
  • Assuming else runs when a condition is true
4. Find the error in this else if ladder code:
let num = 10;
if (num > 10) {
  console.log('Greater than 10');
} else if num > 5 {
  console.log('Greater than 5');
} else {
  console.log('5 or less');
}
medium
A. No error, code is correct
B. Missing curly braces in if block
C. Using else if instead of else
D. Missing parentheses around condition in else if

Solution

  1. Step 1: Check syntax of else if condition

    In JavaScript, conditions must be inside parentheses, but here else if condition lacks parentheses.
  2. Step 2: Confirm other parts are correct

    Curly braces are present, and else if is correctly used, so no other syntax errors.
  3. Final Answer:

    Missing parentheses around condition in else if -> Option D
  4. Quick Check:

    Conditions need parentheses [OK]
Hint: Always put conditions inside parentheses [OK]
Common Mistakes:
  • Forgetting parentheses in else if
  • Confusing else if with else
  • Missing curly braces
5. You want to assign a grade based on score using else if ladder. Which code correctly assigns 'Pass' if score is 50 or more, 'Fail' if less, and 'Invalid' if score is negative?
let score = 45;
if (score < 0) {
  console.log('Invalid');
} else if (score >= 50) {
  console.log('Pass');
} else {
  console.log('Fail');
}
hard
A. Correctly assigns grades as per conditions
B. Fails to check negative score first
C. Pass and Fail conditions are swapped
D. Missing else if for negative score

Solution

  1. Step 1: Check order of conditions

    Negative score is checked first, so invalid scores are caught early.
  2. Step 2: Verify pass and fail conditions

    Score >= 50 prints 'Pass', else prints 'Fail'. This matches requirements.
  3. Final Answer:

    Correctly assigns grades as per conditions -> Option A
  4. Quick Check:

    Order and conditions correct = Correctly assigns grades as per conditions [OK]
Hint: Check invalid cases first in else if ladder [OK]
Common Mistakes:
  • Checking pass before invalid score
  • Swapping pass and fail conditions
  • Missing else block for fail
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard