점검
<script>
/*
[문제]
아래 보기를 참고하여 삼각형을 출력하시오.
[보기]
0
12
345
6789
*/
</script>
HTML
복사
정답
<script>
/*
[문제]
아래 보기를 참고하여 삼각형을 출력하시오.
[보기]
0
12
345
6789
*/
// [for문]
let count = 0;
let countMax = 1;
for(let i = 0; i < 10; i++) {
document.write(i);
count += 1;
if(countMax == count) {
count = 0;
countMax += 1;
document.write("<br>");
}
}
document.write("<br>");
// [while문]
let count2 = 0;
let countMax2 = 1;
let i = 0;
while(i < 10) {
document.write(i);
count2 += 1;
if(countMax2 == count2) {
count2 = 0;
countMax2 += 1;
document.write("<br>");
}
i += 1;
}
</script>
HTML
복사


