영상
개념
<script>
/*
[문제]
1~9 사이의 랜덤 숫자 2개를 저장하고
그 숫자의 합이 무조건 10이 되도록 출력하시오.
[예시]
x = 9
y = 1
*/
let run = true;
while(run) {
let x = Math.floor(Math.random() * 9) + 1; // [0 ~ 8] + 1
let y = Math.floor(Math.random() * 9) + 1; // [0 ~ 8] + 1
let total = x + y;
if(total == 10) {
console.log("x = " + x + ", y = " + y);
document.write("x = " + x + ", y = " + y);
run = false;
}
}
</script>
Java
복사