2.13~2.15 conditonals
const age = prompt("how old are you?");//๋ฉ์์ง ์ฐฝ์ ๋์
console.log(typeof age);//typeof : value์ type ํ์ธ๊ฐ๋ฅ
console.log(age, paraseInt(age));//paraseInt:string ์ number๋ก ๋ณํ์์ผ์ค
const age =parseInt(prompt("How old are you"));
console.log(isNaN(age));//
//์ธ์(age) ๊ฐ์ ์ซ์์ธ์ง ์๋์ง booleanํ์
์ผ๋ก ํ๋ณ
//true ๋ฌธ์ , false ์ซ์
const age =parseInt(prompt("How old are you"));
if (isNaN(age)) { //if ๋ฌธ์์ ์กฐ๊ฑด์ true.false๋ก ํ๊ฒฐ๊ฐ๋ฅํ๊ฒ
console.log("please write a number");
} else if(age < 19) {
console.log("you are too young");
} else {
console.log("you can drink");
}
//true :๋ฌธ์๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ "please write a number" ์ถ๋ ฅ
//19 > age "you are too young"
//19 < age "you can drink"
if (isNaN(age) || age < 0 ) { //if ๋ฌธ์์ ์กฐ๊ฑด์ true.false๋ก ํ๊ฒฐ๊ฐ๋ฅํ๊ฒ
console.log("please write a real positive number");
} else if(age < 19) {
console.log("you are too young");
} else if (age >=19 && age =<50) {
console.log("you can drink");
} else {
console.log("you can't drink");
}
// || or , ๋์ค ํ๋ true && and ๋๋ค true
//else๋ ์ต์
์ฌํญ
ํญ์ ์ด์ฌํ ์ ๋ฆฌํ์๋ค์. ์ค๋๋ ์๊ณ ํ์ จ์ต๋๋ค!๐