Conditional Operator
ternary within template literal... (Jonas 28)
by trentHarlem
JavaScript
// The Conditional (Ternary) Operator
const age = 28;
//const age = 17;
// age >= 18 ? console.log('I like to drink wine π·') : console.log('I like to drink water π§');
//const drink = age >= 18 ? 'wine π·' : 'water π§';
//console.log(drink);
/* let drink2;
if (age >= 18) {
drink2 = 'wine π·';
} else {
drink2 = 'water π§';
} */
//console.log(drink2);
console.log(`I like to drink ${age >= 18 ? 'wine π·' : 'water π§'}`);
// replace switch w ternary
let day = 'frinesursday';
day === 'monday' ?
console.log('Plan course structure') :
day === 'tuesday' ?
console.log('Plan course structure') :
day === 'wednesday' || day === 'thursday' ?
console.log('Plan weekend trip') :
day === 'friday' ?
console.log('Friday', 'Record song ideas') :
day === 'saturday' || day === 'sunday' ?
console.log('Enjoy the weekend :D') :
console.log('Error: Invalid day');