[TIL] Javascript 220603

HJ Kim·2022년 6월 3일
0

TIL

목록 보기
9/27

1. 조건문 (if)

const shoesPrice = 40000
if (shoesPrice < 50000) {
    console.log('이 신발을 사겠습니다.')
}

const capPrice = 50000
if(capPrice < 50000)
{
    console.log('이 모자를 사겠습니다')
}

2. 조건문 (if-else-else if)

  • else
const shoesPrice = 50000
if (shoesPrice < 40000){
    console.log('이 신발을 사겠습니다.')
}
else{
    console.log('너무 비싸요!')
}
  • else if
const shoesPrice = 50000
if (shoesPrice < 40000){
    console.log('이 신발을 사겠습니다.')
} else if (shoesPrice <= 50000){
    console.log('고민을 해볼게요')
}
else{
    console.log('너무 비싸요!')
}

3. 반복문

  • while (종료시킬 조건이 반드시 있어야)
let temperature = 20
while (temperature <= 25){
    console.log('적당한 온도')
    temperature++
}
  • for (조건 변수 선언 및 조건 end 조건을 다 같이 설정)

for (let temperature = 20 ; temperature <= 25 ; ++temperature)
    console.log(`${temperature}는 적당한 온도 입니다.`)
profile
티끌모아 태산을 아는 사람

0개의 댓글