-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_test2.html
407 lines (347 loc) · 11.3 KB
/
number_test2.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>
LearnEra
</title>
<link rel="icon" href="./pictures/logo.jpg" type="image/x-icon" />
<style>
* {
margin: 0;
padding: 0;
font-family: arial;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
.grid {
width: 68%;
height: 520px;
margin: 0 auto;
background-color: rgb(191, 254, 234);
padding: 10px 50px 50px 50px;
border-radius: 50px;
border: 2px solid #cbcbcb;
box-shadow: 10px 15px 5px #cbcbcb;
}
.buttons img {
width: 200px;
}
.red img {
width: 65px;
float: left;
padding-left: 0%;
padding-top: 0%;
filter: invert(1);
}
.mynumber {
width: 100%;
height: 100vh;
background-image: url("./pictures/number.gif");
background-size: cover;
background-position: center;
position: relative;
overflow: hidden;
}
.grid h1 {
font-family: "sans-serif";
background-color: #2f0764;
font-size: 35px;
text-align: center;
color: #ffffff;
padding: 2px 0px;
border-radius: 50px;
}
hr {
margin-top: 50px;
color: red;
background-color: #1f1388;
height: 2px;
border: none;
}
#score {
margin-top: 5%;
color: #43166d;
text-align: center;
font-size: 50px;
}
.grid #question {
font-family: "monospace";
font-size: 50px;
color: #441388;
}
.buttons {
margin-top: 30px;
}
#btn0,
#btn1,
#btn2,
#btn3 {
padding: 0px;
font-size: 20px;
color: #fff;
border: none;
margin: 10px 20px 10px 0px;
}
#btn0:hover,
#btn1:hover,
#btn2:hover,
#btn3:hover {
cursor: pointer;
background-color: #120f05;
}
#btn0:focus,
#btn1:focus,
#btn2:focus,
#btn3:focus {
outline: 0;
}
#progress {
color: #2b2b2b;
font-size: 18px;
}
/* Button
.button button.restart {
color: rgb(3, 95, 216);
background: #f7f7f7;
}
.button button.restart:hover {
color: #ffffff;
background: #149ee3;
}
.button button.quit {
color: rgb(3, 95, 216);
background: #f7f7f7;
}
.button button.quit:hover {
color: #fff;
background: #007bff;
} */
.button button.restart {
margin-left: 10%;
margin-top: 100px;
padding: 20px;
font-size: 25px;
cursor: pointer;
background-color: rgb(11, 102, 247);
color: white;
border: 0cm;
border-radius: 5px;
box-shadow: 0px 5px 10px black;
text-transform: uppercase;
}
.button button.quit {
margin-right: 17%;
margin-top: 100px;
position: relative;
padding: 20px;
font-size: 25px;
cursor: pointer;
background-color: rgb(11, 102, 247);
color: white;
border: 0cm;
border-radius: 10px;
box-shadow: 0px 5px 10px black;
text-transform: uppercase;
}
.button button.restart:hover {
background-color: rgb(17, 194, 35);
transform: scale(1.1);
}
.button button.quit:hover {
background-color: rgb(236, 12, 12);
transform: scale(1.1);
}
.button {
width: 1000px;
display: flex;
justify-content: space-around;
}
/* footer {
height: 40px;
padding: 0 13px;
font-size: 18px;
font-weight: 400;
cursor: pointer;
border: none;
outline: none;
color: #fff;
border-radius: 5px;
background: #007bff;
border: 1px solid #007bff;
line-height: 10px;
opacity: 0;
pointer-events: none;
transform: scale(0.95);
transition: all 0.3s ease;
} /*
/* Result Footer
footer{
height: 60px;
padding: 0 30px;
display:flex;
text-align: center;
align-items: center;
justify-content: space-between;
border-top: 1px solid rgb(71, 31, 31);
}
/*
footer button{
height: 40px;
padding: 0 13px;
font-size: 18px;
font-weight: 400;
cursor: pointer;
border: none;
outline: none;
color: rgb(19, 0, 0);
border-radius: 5px;
background: #007bff;
border: 1px solid #007bff;
line-height: 10px;
opacity: 0;
pointer-events: none;
transform: scale(0.95);
transition: all 0.3s ease;
}
footer button:hover{
background: #0263ca;
}
footer button.show{
opacity: 1;
pointer-events: auto;
transform: scale(1);
} */
</style>
</head>
<body>
<div class="mynumber">
<div class="red">
<button onclick="func3();"><img src="./pictures/logo.jpg" alt="Logo"></button>
</div>
<div class="grid">
<div id="quiz">
<h1>Number Quiz</h1>
<hr style="margin-bottom: 20px">
<p id="question"></p>
<div class="buttons">
<button id="btn0"><span id="choice0"></span></button>
<button id="btn1"><span id="choice1"></span></button>
<button id="btn2"><span id="choice2"></span></button>
<button id="btn3"><span id="choice3"></span></button>
</div>
<hr style="margin-top: 50px">
<footer>
<p id="progress">Question x of y</p>
</footer>
</div>
</div>
</div>
<script type="text/javascript">
var images = {
"one": "./pictures/number-learn/one.jpg",
"two": "./pictures/number-learn/two.jpg",
"three": "./pictures/number-learn/three.jpg",
"four": "./pictures/number-learn/four.jpg",
"five": "./pictures/number-learn/five.jpg",
"six": "./pictures/number-learn/six.jpg",
"seven": "./pictures/number-learn/seven.jpg",
"eight": "./pictures/number-learn/eight.jpg",
"nine": "./pictures/number-learn/nine.jpg",
"ten": "./pictures/number-learn/ten.jpg"
}
function populate() {
if (quiz.isEnded()) {
showScores();
} else {
// show question
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
// show options
var choices = quiz.getQuestionIndex().choices;
for (var i = 0; i < choices.length; i++) {
var element = document.getElementById("choice" + i);
element.innerHTML = images[choices[i]] ? '<img src="' + images[choices[i]] + '"/>' : choices[i];
guess("btn" + i, choices[i]);
}
showProgress();
}
};
function guess(id, guess) {
var button = document.getElementById(id);
button.onclick = function () {
quiz.guess(guess);
populate();
}
};
function showProgress() {
var currentQuestionNumber = quiz.questionIndex + 1;
var element = document.getElementById("progress");
element.innerHTML = "Question " + currentQuestionNumber + " of " + quiz.questions.length;
};
function showScores() {
var gameOverHTML = "<h1>Result</h1>";
gameOverHTML += "<div id='score'> Your scores: " + quiz.score + "</div>";
gameOverHTML += "<footer><div class='button'><button class='restart' onclick= 'func1();'>Replay Quiz</button><button class='quit' onclick= 'func2();'>Quit Quiz</button></div></footer>";
var element = document.getElementById("quiz");
element.innerHTML = gameOverHTML;
};
function func2() {
window.history.back();
};
function func1() {
window.location.reload();
};
/* click logo to previous page */
function func3() {
window.history.back();
};
//Quiz
//const result_box = document.querySelector(".button");
//var quit_quiz = document.querySelector(".footer .button .quit");
//quit_quiz.addEventListener('click', () => {
// window.location.reload(); //reload the current window
//});
// create questions
var questions = [
new Question("Which is One?", ["one", "five", "two", "three"], "one"),
new Question("Which is Five?", ["two", "nine", "one", "five"], "five"),
new Question("Which is Ten ?", ["eight", "two", "ten", "seven"], "ten"),
new Question("Which is Eight?", ["ten", "eight", "four", "five"], "eight"),
new Question("Which is 7?", ["seven", "nine", "three", "two"], "seven")
];
function Question(text, choices, answer) {
this.text = text;
this.choices = choices;
this.answer = answer;
}
Question.prototype.isCorrectAnswer = function (choice) {
return this.answer === choice;
}
function Quiz(questions) {
this.score = 0;
this.questions = questions;
this.questionIndex = 0;
}
Quiz.prototype.getQuestionIndex = function () {
return this.questions[this.questionIndex];
}
Quiz.prototype.guess = function (answer) {
if (this.getQuestionIndex().isCorrectAnswer(answer)) {
this.score++;
}
this.questionIndex++;
}
Quiz.prototype.isEnded = function () {
return this.questionIndex === this.questions.length;
}
// create quiz
var quiz = new Quiz(questions);
// display quiz
populate();
</script>
</body>
</html>