-
Notifications
You must be signed in to change notification settings - Fork 0
/
2test.html
109 lines (79 loc) · 2.47 KB
/
2test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html>
<head>
<title>ab-cd</title>
<link rel="icon" type="image/png" href="/images/favicon.png">
</head>
<meta name="viewport" content= "width=device-width, user-scalable=no">
<link rel="stylesheet" href="styles.css">
<body>
<!-- <p id="A"></p>
<p id="B"></p>
<p id="D"></p>
<p id="E"></p> -->
<div class="content">
<div class="empty"> </div>
<div class="numbers">
<a id="AB"></a>
<a>-</a>
<a id="DE"></a>
</div>
<!-- <p id="R"> </p> -->
<br>
<input inputmode="numeric" class="inputfield" type="inputbox" onkeydown = "if (event.keyCode == 13)
document.getElementById('myBtn').click()" id="numb">
<br>
<br>
<button class="Button" id="myBtn" type="button" onclick="myFunction()">CHECK</button>
<p id="empty"></p>
<button class="Block" type="submit" onClick="onRefreshButtonClick()">NEW VALUES</button>
<a class="prompt" style="color:grey" id="demo"></a>
</div>
<script>
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Generate a new set of numbers
function getNewIntsToCheck() {
const a = getRandomInt(2,9);
const b = getRandomInt(0,8);
const d = getRandomInt(1,a-1);
const e = getRandomInt(b+1,9);
const ab ="" + a + b;
const de ="" + d + e;
const result = ab-de;
return { ab, de, result }
}
// Set in parent scope for access in myFunction
// There are other ways to do this, but this should be easy to understand since
// you don't have much experience with JS :)
let res = ""
// Update the UI on the click of the refresh button
function onRefreshButtonClick() {
const { ab, de, result } = getNewIntsToCheck()
// Set res from parent scope
res = result
// document.getElementById("R").innerHTML = result;
document.getElementById("AB").innerHTML = ab;
document.getElementById("DE").innerHTML = de;
}
// Check current numbers in UI against user input and display message
function myFunction() {
let x = document.getElementById("numb").value;
let text;
// Check against res from parent scope, which was set in
// onRefreshButtonClick
if (x == res) {
text = "Correct";
} else {
text = "incorrect";
}
document.getElementById("demo").innerHTML = text;
}
</script>
<!-- <button class="Block" type="submit" onClick="startover()">START OVER</button> -->
<!-- <button class="Block" type="submit" onClick="refreshPage()">NEW VALUES</button> -->
</body>
</html>