Bookcliff / learning

2 stars 0 forks source link

decisions #9

Closed Bookcliff closed 2 years ago

Bookcliff commented 2 years ago
Bookcliff commented 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 :(");

RusseII commented 2 years ago

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 :(");)

RusseII commented 2 years ago

Ternary is used a lot.