자바스크립트
home
2025 자바스크립트 초급 1500제
home

E0304_개념01_개수의초기화

개념

<script> /* [개수의 초기화] - 숫자 1부터 9까지의 숫자를 출력하시오. - 단, 한 줄에는 숫자를 세 개씩만 출력하고, 숫자 세 개를 출력할 때마다 줄을 바꾸어 이어서 출력하시오. */ /* [출력예시] 1 2 3 4 5 6 7 8 9 */ // [for문] let count = 0; for(let i = 1; i < 10; i++) { document.write(i, " "); count += 1; if(count == 3) { document.write("<br>"); count = 0; } } document.write("<br>"); // [while문] let count2 = 0; let i = 1; while(i < 10) { document.write(i, " "); count2 += 1; if(count2 == 3) { document.write("<br>"); count2 = 0; } i += 1; } </script>
HTML
복사

영상