0
0
Javascriptprogramming~20 mins

Why conditional logic is needed in Javascript - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Conditional Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this conditional code?
Look at this JavaScript code. What will it print to the console?
Javascript
const age = 20;
if (age >= 18) {
  console.log('Adult');
} else {
  console.log('Minor');
}
A"Adult"
B"Minor"
Cundefined
DSyntaxError
Attempts:
2 left
💡 Hint
Check the condition if age is 18 or more.
🧠 Conceptual
intermediate
1:30remaining
Why do we use conditional logic in programs?
Choose the best reason why conditional logic is important in programming.
ATo repeat the same code many times
BTo make decisions and run different code based on conditions
CTo store data permanently
DTo make the program run faster
Attempts:
2 left
💡 Hint
Think about how a program chooses what to do next.
Predict Output
advanced
2:00remaining
What will this nested conditional code output?
Check the output of this JavaScript code with nested if-else statements.
Javascript
const score = 75;
if (score >= 90) {
  console.log('Grade A');
} else if (score >= 70) {
  console.log('Grade B');
} else {
  console.log('Grade C');
}
A"Grade A"
BReferenceError
C"Grade C"
D"Grade B"
Attempts:
2 left
💡 Hint
Look at the score and check which condition it meets first.
🔧 Debug
advanced
2:00remaining
Which option causes an error in this conditional code?
Find which code snippet will cause an error when run.
Javascript
const temperature = 30;
if temperature > 25 {
  console.log('Hot');
} else {
  console.log('Cold');
}
Aif temperature > 25 { console.log('Hot'); } else { console.log('Cold'); }
Bif (temperature > 25) { console.log('Hot'); } else { console.log('Cold'); }
Cif (temperature > 25) console.log('Hot'); else console.log('Cold');
Dtemperature > 25 ? console.log('Hot') : console.log('Cold');
Attempts:
2 left
💡 Hint
Check the syntax of the if statement carefully.
🚀 Application
expert
2:30remaining
What is the value of variable result after this code runs?
Consider this code using conditional logic and the ternary operator. What is the final value of result?
Javascript
const num = 10;
const result = num % 2 === 0 ? 'Even' : 'Odd';
A10
B"Odd"
C"Even"
Dundefined
Attempts:
2 left
💡 Hint
Check if 10 is divisible by 2 without remainder.