Ternary Operator in JavaScript
Level 278 keystrokes
This uses a ternary operator to assign 'pass' or 'fail' based on the score.
JavaScript code
// Declare score with the value 851let score = 85;// Ternary operator: condition ? valueIfTrue : valueIfFalse// It's a shorthand for if-else// Since 85 >= 60 is true, grade becomes "pass"2let grade = score >= 60 ? "pass" : "fail";3console.log(grade);Output
pass
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
"× 4;× 3=× 3:× 1?× 1.× 1(× 1)× 1>× 1