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


