Challenge - 5 Problems
If–else Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested if–else
What is the output of the following JavaScript code?
Javascript
let x = 10; if (x > 5) { if (x < 15) { console.log('A'); } else { console.log('B'); } } else { console.log('C'); }
Attempts:
2 left
💡 Hint
Check the conditions step by step.
✗ Incorrect
x is 10, which is greater than 5 and less than 15, so the first if and the nested if both run, printing 'A'.
❓ Predict Output
intermediate2:00remaining
If–else with logical operators
What will this code print to the console?
Javascript
let a = 3; let b = 7; if (a > 5 && b < 10) { console.log('X'); } else { console.log('Y'); }
Attempts:
2 left
💡 Hint
Remember how && works: both conditions must be true.
✗ Incorrect
a > 5 is false (3 > 5 is false), so the whole condition is false, so else runs printing 'Y'.
❓ Predict Output
advanced2:00remaining
If–else with else if branches
What is the output of this code snippet?
Javascript
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'); }
Attempts:
2 left
💡 Hint
Check each condition in order.
✗ Incorrect
75 is not >= 90 or 80 but is >= 70, so it prints 'C'.
❓ Predict Output
advanced2:00remaining
If–else with variable reassignment
What is the value of variable result after running this code?
Javascript
let num = 0; let result; if (num) { result = 'Truthy'; } else { result = 'Falsy'; }
Attempts:
2 left
💡 Hint
Remember how JavaScript treats 0 in conditions.
✗ Incorrect
0 is falsy in JavaScript, so else branch runs setting result to 'Falsy'.
❓ Predict Output
expert2:00remaining
If–else with complex condition and side effects
What will be printed by this code?
Javascript
let x = 5; if ((x += 3) > 7) { console.log(x); } else { console.log(x - 1); }
Attempts:
2 left
💡 Hint
The condition changes x before comparing.
✗ Incorrect
x starts at 5, then x += 3 makes x 8, which is > 7, so it prints 8.