-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath.random().html
More file actions
43 lines (33 loc) · 980 Bytes
/
Math.random().html
File metadata and controls
43 lines (33 loc) · 980 Bytes
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
41
42
43
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript 1</title>
</head>
<body>
<h1> Java Script Random Number</h1>
<p id="problem"></p>
<input id="userInput" type="text">
<button id="checkAnswer" type="button"> Check answer</button>
<script>
var random1= Math.floor(Math.random()*10);
var random2= Math.floor(Math.random()*10);
var problem = random1 + "+" + random2 + "=" ;
document.getElementById("problem").innerHTML=problem;
//after user click on the check item button
document.getElementById("checkAnswer").onclick=function(){
//get the user answer
var userInput= document.getElementById("userInput").value;
var key= random1 + random2;
if(userInput==key){
alert("Great Job!");
}
else{
alert("try again and again ");
}
}
</script>
</body>
</html>