Java Script
[ Java Script ] 랜덤으로 숫자 받아 출력하기
dauneee
2022. 2. 15. 14:01
조건 |
1) 랜덤으로 두개의 숫자 입력 받기 ( 10~99 까지 ) 2) 두개의 수 곱한 값을 맞추면 정답, 틀리면 오답 멘트 출력 |
< 코드 >
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>값 두개 저장</title>
<link rel="shortcut icon" href="">
</head>
<body>
<script type="text/javascript">
const rand1 = Math.floor(Math.random() * 89) + 10; //10부터 99까지의 수
const rand2 = Math.floor(Math.random() * 89) + 10;
var input = prompt(rand1 + 'x' + rand2 + '= ?');
if (input == rand1 * rand2) {
console.log('정답입니다:)');
} else {
console.log('오답입니다:(')
}
</script>
</body>
</html>