0
0
Javascriptprogramming~20 mins

If–else statement in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
If–else 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
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');
}
AB
BC
CA
Dundefined
Attempts:
2 left
💡 Hint
Check the conditions step by step.
Predict Output
intermediate
2: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');
}
AX
BY
Cundefined
DSyntaxError
Attempts:
2 left
💡 Hint
Remember how && works: both conditions must be true.
Predict Output
advanced
2: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');
}
AC
BA
CB
DF
Attempts:
2 left
💡 Hint
Check each condition in order.
Predict Output
advanced
2: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';
}
A'Falsy'
Bundefined
C'Truthy'
DReferenceError
Attempts:
2 left
💡 Hint
Remember how JavaScript treats 0 in conditions.
Predict Output
expert
2: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);
}
A6
B7
C5
D8
Attempts:
2 left
💡 Hint
The condition changes x before comparing.