Search

반복문10_개념01_랜덤업다운

대분류
STEP04 일차반복문
문제 난이도
LV03
소분류
일차반복문10_개념

영상

개념

<script> /* [문제] com은 1~100 사이의 숫자를 한 개 저장한다. me는 com의 숫자를 모른다고 가정하고, 1~100 사이의 숫자를 제시한다. com과 me를 비교해서 "크다", "작다", "같다"를 출력하시오. com은 딱 한 번만 숫자를 정하고, me는 com의 숫자를 맞출 때까지 계속 숫자를 랜덤으로 뽑는다. 숫자를 맞추면 게임은 종료된다. */ let com = Math.floor(Math.random() * 100) + 1; // [0 ~ 99] + 1 console.log("com = " + com); document.write("com = " + com + "<br>"); let run = true; while(run) { let me = Math.floor(Math.random() * 100) + 1; console.log("me = " + me); document.write("me = " + me + "<br>"); if(com < me) { console.log("크다"); document.write("크다<br>"); } else if(com > me) { console.log("작다"); document.write("작다<br>"); } else { console.log("같다"); document.write("같다<br>"); run = false; } } </script>
Java
복사