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

E0306_예제03_문제

예제

<script> /* [문제] 아래 보기를 참고하여 삼각형을 출력하시오. [보기] 00 1122 334455 66778899 */ </script>
HTML
복사

정답

<script> /* [문제] 아래 보기를 참고하여 삼각형을 출력하시오. [보기] 00 1122 334455 66778899 */ // [for문] let count = 0; let countMax = 2; for(let i = 0; i < 20; i++) { let a = parseInt(i / 2); document.write(a); count += 1; if(countMax == count) { count = 0; countMax += 2; document.write("<br>"); } } document.write("<br>"); // [while문] let count2 = 0; let countMax2 = 2; let i = 0; while(i < 20) { let a = parseInt(i / 2); document.write(a); count2 += 1; if(countMax2 == count2) { count2 = 0; countMax2 += 2; document.write("<br>"); } i += 1; } </script>
HTML
복사