Closed Bookcliff closed 2 years ago
if...else statement: if (currentMoney >= laptopPrice) { console.log("I'm getting a new laptop!") } else { console.log("No laptop for me :(") }
Ternary expression: currentMoney >= laptopPrice ? ("I'm getting a new laptop!"): ("No laptop for me :(");
that example is funny. Usually you'll either assign the result to a variable, or return it from a function.
const result = currentMoney >= laptopPrice ? ("I'm getting a new laptop!"): ("No laptop for me :(");
or
return currentMoney >= laptopPrice ? ("I'm getting a new laptop!"): ("No laptop for me :(");
or to match your first example...
console.log(currentMoney >= laptopPrice ? ("I'm getting a new laptop!"): ("No laptop for me :(");)
Ternary is used a lot.