๐Ÿ‘ฉ๐Ÿผโ€๐Ÿ’ป๋ฐ”๋‹๋ผ JS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ : 2.12-2.15

change upยท2023๋…„ 6์›” 1์ผ
2
post-custom-banner

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๋Š” ์˜ต์…˜์‚ฌํ•ญ 
profile
์ƒˆ์‹น์ด
post-custom-banner

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 6์›” 1์ผ

ํ•ญ์ƒ ์—ด์‹ฌํžˆ ์ •๋ฆฌํ•˜์‹œ๋„ค์š”. ์˜ค๋Š˜๋„ ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!๐Ÿ˜Š

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ