Challenge - 5 Problems
Conditional Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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'); }
Attempts:
2 left
💡 Hint
Check the condition if age is 18 or more.
✗ Incorrect
Since age is 20, which is greater than or equal to 18, the code prints "Adult".
🧠 Conceptual
intermediate1:30remaining
Why do we use conditional logic in programs?
Choose the best reason why conditional logic is important in programming.
Attempts:
2 left
💡 Hint
Think about how a program chooses what to do next.
✗ Incorrect
Conditional logic lets programs decide what to do based on different situations or inputs.
❓ Predict Output
advanced2: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'); }
Attempts:
2 left
💡 Hint
Look at the score and check which condition it meets first.
✗ Incorrect
Score 75 is not >= 90 but is >= 70, so it prints "Grade B".
🔧 Debug
advanced2: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'); }
Attempts:
2 left
💡 Hint
Check the syntax of the if statement carefully.
✗ Incorrect
Option A is missing parentheses around the condition, causing a SyntaxError.
🚀 Application
expert2: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';
Attempts:
2 left
💡 Hint
Check if 10 is divisible by 2 without remainder.
✗ Incorrect
10 % 2 equals 0, so the condition is true and result is set to "Even".