개념
<script>
/*
[무한반복과 경우의 수2]
- 숫자 1부터 3 사이의 랜덤 숫자를 무한히 출력합니다.
- 숫자 1이 연속으로 3번 나오면 종료합니다.
*/
/*
[출력예시]
1 3 3 2 2 2 3 2 3 1 3 1 2 2 1 3 2 3 3 3 3 2 1 3 1 3 1 1 1
*/
let count = 0;
while(true) {
let r = Math.floor(Math.random() * 3) + 1;
document.write(r, " ");
if(r == 1) {
count += 1;
} else if(r != 1) {
count = 0;
}
if(count == 3) {
break;
}
}
</script>
HTML
복사


