if (age > 19) { canDrinkAlcohol = "OK. You can buy alcohol."; } else { canDrinkAlcohol = "No. You can't buy alcohol."; } console.log(canDrinkAlcohol);
if문을 삼항조건연산자로 써보기
1 2 3 4 5 6
var age = 19; var canDrinkAlcohol = "";
canDrinkAlcohol = age > 19 ? "OK. You can buy alcohol." : "No. You can't buy alcohol."; console.log(canDrinkAlcohol);
신장을 출력하는 if문
1 2 3 4 5 6 7 8 9 10
var height = 169; var result = "";
var result = height > 169 ? "wow, you are taller than me" : height < 169 ? "You are little bit shorter than me." : "You and me are the same height."; console.log(result);
if문을 삼항조건연산자로 써보기
1 2 3 4 5 6 7 8 9 10
var height = 169; var result = "";
if (height > 169) { console.log("wow, you are taller than me"); } elseif (height < 169) { console.log("You are little bit shorter than me."); } else { console.log("You and me are the same height."); }