조건문 ( if , else, and, or)
if
if 조건은 항상 참이어야함
if(10 === 5){ // 5보다 10이 큰지 체크함
// 만약 10 > 5 -> hi 출력
console.log("hi")
}else if(10 === "10"){
console.log("ho")
}
else{
console.log("no") // no 출력
}
if(20 > 5 && "boo" ==== "boo"){
// && 두가지의 조건이 다 충족되야함
// || or이라서 하나만 충족되도됨
console.log("yes") // yes 출력
}else{
console.log("no")
}
const age = prompt(" 몇살이야? ");
if(age >= 18 && age <= 21 ){ // 18살 21사이 일때
console.log(" you can drink you shold not");
}else if(age > 21){ //21살보다 많을때
colsole.log(" go ahead ")
}else{// 두조건이 다 아닐때
console.log(" too young ");
}
if else
Last updated
Was this helpful?