0
0
Javascriptprogramming~20 mins

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

Choose your learning style9 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.