0
0
Javascriptprogramming~20 mins

Nested conditional statements in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Conditionals Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested if-else with number checks
What is the output of the following code snippet?
Javascript
const num = 15;
if (num > 10) {
  if (num < 20) {
    console.log('A');
  } else {
    console.log('B');
  }
} else {
  console.log('C');
}
AB
BA
CC
Dundefined
Attempts:
2 left
💡 Hint
Check the conditions step by step starting from the outer if.
Predict Output
intermediate
2:00remaining
Nested conditionals with string comparison
What will be logged to the console?
Javascript
const color = 'red';
if (color === 'blue') {
  if (color.length > 3) {
    console.log('Blue and long');
  } else {
    console.log('Blue and short');
  }
} else {
  console.log('Not blue');
}
Aundefined
BBlue and short
CBlue and long
DNot blue
Attempts:
2 left
💡 Hint
Check the first condition comparing the color variable.
Predict Output
advanced
2:00remaining
Output of nested ternary operators
What is the output of this code?
Javascript
const x = 5;
const y = 10;
const result = x > 3 ? (y < 10 ? 'A' : 'B') : 'C';
console.log(result);
AC
Bundefined
CB
DA
Attempts:
2 left
💡 Hint
Evaluate the outer condition first, then the inner ternary.
Predict Output
advanced
2:00remaining
Nested if-else with multiple conditions
What will be the output of this code?
Javascript
const score = 75;
if (score >= 90) {
  console.log('A');
} else {
  if (score >= 70) {
    console.log('B');
  } else {
    console.log('C');
  }
}
AB
BC
CA
Dundefined
Attempts:
2 left
💡 Hint
Check the score against 90 first, then 70.
Predict Output
expert
3:00remaining
Complex nested conditionals with logical operators
What is the output of this code snippet?
Javascript
const a = 4;
const b = 7;
if (a > 3) {
  if (b < 5) {
    console.log('X');
  } else if (b === 7) {
    console.log('Y');
  } else {
    console.log('Z');
  }
} else {
  console.log('W');
}
AY
BX
CZ
DW
Attempts:
2 left
💡 Hint
Check each nested condition carefully in order.