Predict Ternary Output
Predict Output Easy
Question
What does this code print?
Code
const score = 85;
const grade = score >= 90 ? "A" : score >= 80 ? "B" : "C";
console.log(grade);
Hint
Ternary operators can be chained. Evaluate left to right.
Explanation
First, score >= 90 is 85 >= 90 = false, so we go to the next ternary. score >= 80 is 85 >= 80 = true, so the result is "B". Chained ternaries act like an if/else-if/else chain.
Related Resources
Related Lessons
- Conditions
Learn about ternary operators.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.