자바스크립트
home
2025 자바스크립트 초급 1500제
home

D0403_개념01_기억과개수

개념

<script> /* [기억과 개수] - 랜덤 숫자 4개를 저장한 후, - 가장 첫 번째 짝수를 출력하시오. */ /* [출력예시] 3 2 4 1 2 */ let r = Math.floor(Math.random() * 10) + 1; let r2 = Math.floor(Math.random() * 10) + 1; let r3 = Math.floor(Math.random() * 10) + 1; let r4 = Math.floor(Math.random() * 10) + 1; document.write(r, " ", r2, " ", r3, " ", r4, "<br>"); let count = 0; let a = 0; if(count == 0 && r % 2 == 0) { a = r; count += 1; } if(count == 0 && r2 % 2 == 0) { a = r2; count += 1; } if(count == 0 && r3 % 2 == 0) { a = r3; count += 1; } if(count == 0 && r4 % 2 == 0) { a = r4; count += 1; } document.write(a); </script>
HTML
복사

영상