|
const age = parseInt( prompt("How old are you?") );
// parseInt : string -> number , string is not a number -> "NaN"
if(isNaN(age) || age < 0) {
console.log("Please write a real positive number"); // if NaN (true)-> "Please write a number"
} else if(age < 18) {
console.log("You are too young."); // age < 18 -> "You are too young."
} else if(age >=18 && age<=80) {
console.log("You can drink"); // 18>=age<=50 -> "You can drink"
} else {
console.log("You shouldn't drink for health"); // age>50 -> "You shouldn't drink for health"
}
|
parseInt : string -> number , string is not a number -> "NaN"
isNaN : boolean값을 반환(true/false)
or : || (하나만 true여도 true)
and : && (모두 true여야 true)
'Frontend > Javascript' 카테고리의 다른 글
| Events listening (0) | 2021.12.20 |
|---|---|
| HTML in Javascript (0) | 2021.12.20 |
| Function (0) | 2021.12.16 |
| Array / object (0) | 2021.12.15 |
| variables (0) | 2021.12.15 |