점검
<script>
/*
[문제]
랜덤 숫자 4개를 저장한 후,
가장 마지막 홀수를 출력하시오.
*/
/*
[출력예시]
7 1 6 5
5
*/
</script>
HTML
복사
정답
<script>
/*
[문제]
랜덤 숫자 4개를 저장한 후,
가장 마지막 홀수를 출력하시오.
*/
/*
[출력예시]
7 1 6 5
5
*/
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 a = 0;
if(r % 2 == 1) {
a = r;
}
if(r2 % 2 == 1) {
a = r2;
}
if(r3 % 2 == 1) {
a = r3;
}
if(r4 % 2 == 1) {
a = r4;
}
document.write(a);
</script>
HTML
복사