반복문 복습

sunnychu·2023년 4월 23일

SEBFE45

목록 보기
6/19

1부터 10까지 반복문 출력하기

for(let j = 1; j <= 10; j++){
    console.log(j)
}

1부터 10까지 짝수만 출력하기

for(let i = 1; i <= 10; i++){
   if(i % 2 === 0) {
    console.log(i)
   }
}

1부터 10까지 홀수만 출력하기

for(let j = 1; j <= 10; j++){
    if(j % 2 === 1){
    console.log(j)
    }
}

이중 반복문 (구구단)

for(let i = 2; i < 10; i++){
    console.log(`${i}`)
    for(let j = 1; j < 10; j++){
        console.log(`${i} x ${j} = ${i*j}`)
    }
}

0개의 댓글