-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreater-than-less-than.html
191 lines (156 loc) · 4.59 KB
/
greater-than-less-than.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<html>
<head>
<!--
TODO fix number sizes for mobile
TODO fix single digit numbers
-->
<script src="js/global.js"></script>
<style>
body {
display: flex;
flex-direction: column;
height: 100vh;
}
#top, #middle, #bottom {
display: flex;
justify-content: center;
}
#top {
height: 33%;
align-items: flex-end;
}
#middle {
flex: 1;
align-items: center;
}
#bottom {
height: 33%;
align-items: flex-start;
}
#left-number, #right-number {
font-size: 10vw;
}
#left-number {
display: flex;
justify-content: flex-end;
padding-right: 3vw;
}
#right-number {
padding-left: 3vw;
}
#answer {
border-bottom: solid 0.5vw black;
min-width: 150px;
display: flex;
align-items: flex-end;
justify-content: center;
}
#less-than {
margin-right: 2vw;
}
#new-problem {
display: none;
}
#greater-than {
margin-right: 2vw;
}
#score {
position: absolute;
bottom: 0;
right: 1vh;
font-size: 8vh;
}
#correct, #incorrect {
display: none;
}
</style>
</head>
<body class="no-select">
<script>
window.uuid = 'ec646932-ff31-11ea-adc1-0242ac120002';
window.score = parseInt(localStorage.getItem(`${uuid}::score`)) || 0;
window.incorrectAnswer = false;
function newProblem() {
if (!window.incorrectAnswer) {
window.left = Math.floor(Math.random() * 101);
do {
window.right = Math.floor(Math.random() * 101);
} while(window.right === window.left);
}
document.getElementById('left-number').innerHTML = window.left;
document.getElementById('right-number').innerHTML = window.right;
reset();
}
function correct() {
window.score += 1;
localStorage.setItem(`${window.uuid}::score`, window.score);
document.getElementById('correct').style.display = 'block';
document.getElementById('incorrect').style.display = 'none';
}
function incorrect() {
window.incorrectAnswer = true;
document.getElementById('correct').style.display = 'none';
document.getElementById('incorrect').style.display = 'block';
}
function updateScore() {
document.getElementById('score').innerText = window.score;
}
function hideAnswerButtons() {
document.getElementById('new-problem').style.display = 'block';
document.getElementById('less-than').style.display = 'none';
document.getElementById('greater-than').style.display = 'none';
}
function reset() {
window.incorrectAnswer = false;
document.getElementById('new-problem').style.display = 'none';
document.getElementById('less-than').style.display = 'block';
document.getElementById('greater-than').style.display = 'block';
document.getElementById('correct').style.display = 'none';
document.getElementById('incorrect').style.display = 'none';
document.getElementById('answer').classList.remove('solid-less-than');
document.getElementById('answer').classList.remove('solid-greater-than');
}
function selectLessThan() {
hideAnswerButtons();
document.getElementById('answer').classList.remove('solid-greater-than');
document.getElementById('answer').classList.add('solid-less-than');
if (window.left < window.right) {
correct();
} else {
incorrect();
}
updateScore();
}
function selectGreaterThan() {
hideAnswerButtons();
document.getElementById('answer').classList.remove('solid-less-than');
document.getElementById('answer').classList.add('solid-greater-than');
if (window.left > window.right) {
correct();
} else {
incorrect();
}
updateScore();
}
window.addEventListener('load', () => {
updateScore();
newProblem();
});
</script>
<div id="top">
<div id="left-number"></div>
<div id="answer" class="icon-9"></div>
<div id="right-number"></div>
</div>
<div id="middle">
<div id="correct" class="solid-check icon-9 icon-green"></div>
<div id="incorrect" class="solid-times icon-9 icon-red"></div>
</div>
<div id="bottom">
<div id="less-than" class="button solid-less-than icon-7" onclick="selectLessThan()"></div>
<div id="new-problem" class="button solid-sync-alt icon-7" onclick="newProblem()"></div>
<div id="greater-than" class="button solid-greater-than icon-7" onclick="selectGreaterThan()"></div>
</div>
<div id="score">0</div>
</body>
</html>