점검
<script>
/*
[문제]
아래 보기를 참고하여 삼각형을 출력하시오.
[보기]
11
2222
333333
44444444
*/
</script>
HTML
복사
정답
<script>
/*
[문제]
아래 보기를 참고하여 삼각형을 출력하시오.
[보기]
11
2222
333333
44444444
*/
// [for문]
let count = 0;
let countMax = 2;
for(let i = 0; i < 20; i++) {
document.write(countMax / 2);
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) {
document.write(countMax2 / 2);
count2 += 1;
if(countMax2 == count2) {
count2 = 0;
countMax2 += 2;
document.write("<br>");
}
i += 1;
}
</script>
HTML
복사


