-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.html
40 lines (35 loc) · 968 Bytes
/
random.html
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
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
<script>
function randomNum() {
var num1 = document.getElementById("numb1");
var num2 = document.getElementById("numb2");
num1.innerHTML = Math.floor(Math.random()*10+1);
num2.innerHTML = Math.floor(Math.random()*10+1);
}
function checkMath() {
var num1 = parseInt(document.getElementById("numb1").innerHTML);
var num2 = parseInt(document.getElementById("numb2").innerHTML);
var answer = parseInt(document.getElementById("answer").value);
if (answer == num1 + num2) {
alert("correct");
} else {
alert(answer + " is incorrect, please enter correct answer ");
location.reload();
}
}
</script>
</head>
<body onLoad="randomNum();">
<table border="2px">
<tr>
<td id="numb1"></td>
<td>+</td>
<td id="numb2"></td>
</tr>
</table>
<form id="problem"><p><input id="answer" value=""></p>
<input type="button" onclick="checkMath();" value="Check Answer"></form>
</body>
</html>