Challenge - 5 Problems
Nested Conditionals Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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'); }
Attempts:
2 left
💡 Hint
Check the conditions step by step starting from the outer if.
✗ Incorrect
The number 15 is greater than 10, so the outer if is true. Then inside, 15 is less than 20, so it prints 'A'.
❓ Predict Output
intermediate2: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'); }
Attempts:
2 left
💡 Hint
Check the first condition comparing the color variable.
✗ Incorrect
The color is 'red', which is not equal to 'blue', so the else block runs and prints 'Not blue'.
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
Evaluate the outer condition first, then the inner ternary.
✗ Incorrect
x is 5 which is > 3, so check y < 10. y is 10, not less than 10, so result is 'B'.
❓ Predict Output
advanced2: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'); } }
Attempts:
2 left
💡 Hint
Check the score against 90 first, then 70.
✗ Incorrect
Score 75 is not >= 90, so outer else runs. Then 75 >= 70 is true, so prints 'B'.
❓ Predict Output
expert3: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'); }
Attempts:
2 left
💡 Hint
Check each nested condition carefully in order.
✗ Incorrect
a is 4 > 3 true, then b is 7, not < 5, but equals 7, so prints 'Y'.