What is ternary ?
condition ? true : false
Example
const age = 14;
const result = age >= 18 ? "You can Drive" : "You cannot drive";
console.log(result);
Tasks -
isPremium = true/false).price > 1000 ? 10% discount : 5% discount).Nested Ternary
condition1 ? true1 : condition2 ? true2 : false
const grade = marks >= 90 ? 'A+' : marks >= 80 ? 'A' : 'B+';
Task -
Check if temperature is hot, cold, or normal using nested ternary.
Return good morning, afternoon or evening according to the time.
Make the grading system of Nepal with nested ternary.
A: 80 to below 90%
B+: 70 to below 80%
B: 60 to below 70%
C+: 50 to below 60%
C: 40 to below 50%
D: 35 to below 40% (Passing grade)
NG (Non-Graded): Below 35%