점검
<script>
/*
[문제]
반복문을 사용해서 보기와 같이 출력하시오.
[보기]
19 19
16 35
13 48
10 58
7 65
4 69
1 70
*/
</script>
HTML
복사
정답_for문
<script>
/*
[문제]
반복문을 사용해서 보기와 같이 출력하시오.
[보기]
19 19
16 35
13 48
10 58
7 65
4 69
1 70
*/
let total = 0;
for(let i = 19; i >= 0; i -= 3){
total += i;
document.write(i, " ", total, "<br>");
}
document.write("<br>");
let total2 = 0;
for(let i = 0; i < 7; i++) {
let a = 19 - i * 3;
total2 += a;
document.write(a, " ", total2, "<br>");
}
</script>
HTML
복사
정답_while문
<script>
/*
[문제]
반복문을 사용해서 보기와 같이 출력하시오.
[보기]
19 19
16 35
13 48
10 58
7 65
4 69
1 70
*/
let total = 0;
let i = 19;
while(i >= 0) {
total += i;
document.write(i, " ", total, "<br>");
i -= 3;
}
document.write("<br>");
let total2 = 0;
let i2 = 0;
while(i2 < 7) {
let a = 19 - i2 * 3;
total2 += a;
document.write(a, " ", total2, "<br>");
i2 += 1;
}
</script>
HTML
복사


