For this exercise, simply review some of our earlier examples of IF, ELSE, and ELSE-IF statements and convert them to use the ternary operator and related syntax. I've also placed some very simple scenarios below based on our earliest on-screen examples that you can try as well.
let number = 3;
console.log(number > 0 ? "The number is positive" : "The number is negative");
Nested Example with "else" (negative outcome):
let age = 8;
let message = (age < 9) ? 'Below age 3!' :
(age < 18) ? 'Below age 18!' :
(age < 100) ? 'Below age 100!' :
'Over 100!';
console.log(message);
Scenarios:
Write a program that checks if a number is positive or negative and reports the result.
Write a program that compares two numbers and reports which one is larger.
Write a JavaScript program that lets a user input a number, then classifies that number as "positive", "negative", or "zero" and prints the classification to the console.
Write a JavaScript program that classifies a student's grade as "A", "B", "C", "D", or "F" based on a numeric
score and prints the classification to the console.
User inputs a number between 1 and 7 (inclusive); program responds with what day of the week that is (Sunday = 1).
For this exercise, simply review some of our earlier examples of IF, ELSE, and ELSE-IF statements and convert them to use the ternary operator and related syntax. I've also placed some very simple scenarios below based on our earliest on-screen examples that you can try as well.
Info on Ternary: https://javascript.info/ifelse
Simple Example:
Nested Example with "else" (negative outcome):
Scenarios: