Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Amarans

웹 화면에서 구구단 게임 본문

카테고리 없음

웹 화면에서 구구단 게임

Amarans 2020. 5. 5. 18:03

html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
</head>
<body>  
    <div id="문제"></div>
    <form id="폼">
    <input type="number" id="m2">
    <button id="버튼">입력</button>
    </form>
    <div id="결과창">딩동댕</div>
<script src="구구단.js">
</script>
</body>
</html> 

구구단.js

var 숫자1 = Math.ceil(Math.random() * 9)
var 숫자2 = Math.ceil(Math.random() * 9)
var 결과 = 숫자1 * 숫자2

var m2 = document.getElementById("m2");
var 문제 = document.getElementById("문제");
문제.textContent = String(숫자1) + "곱하기" + String(숫자2) + "는?";
var 폼 = document.getElementById("폼");
var 버튼 = document.getElementById("버튼");
var 결과창 = document.getElementById("결과창");

폼.addEventListener("submit" , function gugudan(e) {
    e.preventDefault();
 if(결과 === Number(m2.value)) {
     결과창.textContent = "딩동댕"
     숫자1 = Math.ceil(Math.random() * 9);
     숫자2 = Math.ceil(Math.random() * 9);
     결과 = 숫자1 * 숫자2;
     문제.textContent = String(숫자1) + "곱하기" + String(숫자2) + "는?";
     m2.value = '';
     m2.focus();
 }else{
     결과창.textContent="땡";
     m2.value = '';
     m2.focus();
 }
});

Comments