-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathquizz.html
553 lines (484 loc) · 25 KB
/
quizz.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
crossorigin="anonymous"></script>
<title>Financial Development</title>
<link rel="icon" href="./Assets/icon2.png" type="image/icon" sizes="16x16">
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
</head>
<body>
<style>
.wider{width: 100%;}
.row {
text-align: center;
}
.hidden {
display: none;
}
.visuallyhidden {
opacity: 0;
}
.accordion-button {
color:white;
}
/* .accordion-button:not(.collapsed) {
color: rgb(235, 83, 24);
background-color: transparent;
} */
.accordion-button:not(.collapsed)::after {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23212529'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
transform: rotate(180deg);
}
@media only screen and (min-width: 800px) {
/* Medium and Large devices (laptops/desktops, 800px and up) */
.accordion-body2 {
/* padding: 1rem 43%; */
}
.accordion-button {
display: block;
color:white;
}
.score-button {
width: 40%;
margin: auto;
}
}
@media only screen and (max-width: 799px) {
/* small devices (laptops/desktops, 800px and up) */
.score-button {
width: 100%;
margin: auto;
}
h5{
font-size: 13.28px;
}
}
button {
display: block;
margin: 0 auto;
}
.accordion-button:not(.collapsed) {
color:white;
background-color: transparent;
}
.accordion-button:focus {
z-index: 3;
border-color: rgb(255, 251, 249);
outline: 0;
box-shadow: 0 0 0 0.25rem white;
}
.accordion-collapse1 {
border: solid rgba(245, 238, 238, 0.836);
background-color: rgb(247, 241, 239);
color: rgb(9, 11, 58);
border-width: 0 1px;
text-align: center;
margin: auto;
}
.accordion-button {width: fit-content;}
.accordion-flush .accordion-item:first-of-type .accordion-button {
background-color: transparent;
color:white;
}
#myProgress {
padding: 10px;
width: 100%;
background-color: rgb(247, 242, 240);
}
.correct {
color: rgb(10, 146, 236);
}
.wrong {
color: rgb(252, 140, 49);
}
.input-group .btn{color: white;}
#myBar {
width: 100%;
height: 20px;
background-color: rgb(9, 11, 58);
text-align: center;
line-height: 20px;
color: white;
}
h1,
h3 {
text-align: center;
}
.box {
margin: 30px auto;
transition: all 1s linear;
}
.full-height{
min-height: calc(100vh - 18.7rem)}
</style>
<header>
<h1 class="abc">Essential Finance</h1>
</header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid" style="background-color: rgb(9, 11, 58) ;">
<a class="navbar-brand" href="index.html" style="background-color: rgb(9, 11, 58) ;color: white;">Financial
Education
101</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"
style="background-color:white">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav nav-tabs ">
<li class="nav-item">
<a class="nav-link li1" aria-current="page" href="index.html" style="color: white;">Home</a>
</li>
<li class="nav-item">
<a onclick="getArticles()" class="nav-link li1" href="stockNews.html" style="color: white;">Stock
News</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle centertabs active" href="#" id="navbarDropdownMenuLink"
role="button" data-bs-toggle="dropdown" aria-expanded="false" style="color: rgb(9, 11, 58) ;">
KnowledgeBase
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="flashcard.html">Flash Cards</a></li>
<li><a class="dropdown-item active" href="quizz.html"
style="color: rgb(9, 11, 58) ;">Quiz</a></li>
<li><a class="dropdown-item" href="videolectures.html">Video Lectures</a></li>
<!-- <li><a class="dropdown-item" href="#">Something else </a></li> -->
</ul>
</li>
<!-- <li class="nav-item">
<a class="nav-link li1" href="videolectures.html" style="color: white;">video Lectures</a>
</li> -->
<li class="nav-item">
<a class="nav-link" href="contact.html" style="color: white;">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- <h1></h1> -->
<div class="accordion accordion-flush" id="accordionFlushExample">
<div class="accordion-item">
<h2 class="accordion-header" id="flush-headingOne" style="margin-top: 0.4%;">
<button class="accordion-button collapsed " type="button" data-bs-toggle="collapse"
data-bs-target="#flush-collapseOne" aria-expanded="false" aria-controls="flush-collapseOne">
<h4>Instructions</h4>
</button>
</h2>
<div id="flush-collapseOne" class="accordion-collapse accordion-collapse1 collapse"
aria-labelledby="flush-headingOne" data-bs-parent="#accordionFlushExample">
<div class="accordion-body">
<h5 style="text-align: center;">This quiz consists of questions related to finance.
There will be a timer of 200 seconds after you click the Start button.
If you answer correctly your score increases by 10 points whereas if you answer wrong
the score decreases by 5 % ! Once you answer a question you can't return back to it.
The quiz ends by answering all the questions or when the time is up.
Good Luck having your name in the top of the Highscore List!</h5>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="flush-headingTwo">
<button onclick="saveScoreBefore()" class="accordion-button collapsed" type="button"
data-bs-toggle="collapse" data-bs-target="#flush-collapseTwo" aria-expanded="false"
aria-controls="flush-collapseTwo">
<h4>HighScore</h4>
</button>
</h2>
<div id="flush-collapseTwo" class="accordion-collapse collapse" aria-labelledby="flush-headingTwo"
data-bs-parent="#accordionFlushExample">
<div class="accordion-body accordion-body2">
<h5>
<div class="card" style="width: fit-content; margin: auto;">
<div class="card-header" style="color: rgb(9, 11, 58); text-align: center;">
HighScores
</div>
<ul class="list-group list-group-flush" style=" text-align: center; color:black;"
id="list-group">
</ul>
<div class="card-footer">
<button onclick="clearAll()" class="btn btn-light wider" style="background-color: rgb(9, 11, 58) ;color: white;">Clear Scores</button>
</div>
</div>
</h5>
</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-3"></div>
<div class="col-6">
<div id="myProgress">
<div id="myBar">1 Minute Timer</div>
</div>
</div>
<div class="col-3"></div>
</div>
<div>
<p id="answerOutput" style="text-align: center;"> </p>
</div>
<div class="container full-height test3" >
<div class="row box question1 " id="box1">
<div class="col-3"></div>
<div class="col-6"><button onclick="hideQuestion()" id="button1" style="width: 100%;">Start The
Quiz</button></div>
<div class="col-3"></div>
</div>
<div class="row box question2 hidden visuallyhidden " id="box2"></div>
<div class="row box question3 hidden visuallyhidden" id="box3"></div>
<div class="row box question4 hidden visuallyhidden" id="box4"></div>
<div class="row box question5 hidden visuallyhidden" id="box5"></div>
<div class="row box question6 hidden visuallyhidden" id="box6"></div>
<div class="row box question7 hidden visuallyhidden" id="box7"></div>
<div class="row box question8 hidden visuallyhidden" id="box8"></div>
<div class="row box question9 hidden visuallyhidden" id="box9"></div>
<div class="row box question10 hidden visuallyhidden" id="box10"></div>
<div class="row box finished hidden visuallyhidden" id="box11"></div>
</div>
<script src="script.js"></script>
<script>
var quizzQuestions = {
quest2: { question: "What is a stock?", answer1: "An investment tool that represents ownership in a company. An investor profits from the increase in the growth of the company, which then results in their stock increasing in price as well", answer2: "type of company that you can hold to buy a house", answer3: "a type of line of credit to make you a lot of money", correctAnswer: "An investment tool that represents ownership in a company. An investor profits from the increase in the growth of the company, which then results in their stock increasing in price as well" },
quest3: { question: "What are bonds?", answer1: "A bond is a type of promise a bank makes to their clients for the future", answer2: "Bonds are a “fixed income” investment tool that is basically a loan made from an investor, to a borrower (usually a company).", answer3: "It is a form of investment to help reduce your taxes in the future", correctAnswer: "Bonds are a “fixed income” investment tool that is basically a loan made from an investor, to a borrower (usually a company)." },
quest4: { question: "What are GICs and treasury bills?", answer1: "A GIC is a guaranteed investor counsel who help you find good investments", answer2: "A GIC is a guaranteed investment certificate that guarantees your invested amount with some interest.", answer3: "A GIC is a good investment calculator which calculates how much return you earn from your investment", correctAnswer: "A GIC is a guaranteed investment certificate that guarantees your invested amount with some interest." },
quest5: { question: "What is a savings and chequing account?", answer1: "A chequing account is often used as an account for keeping cash for everyday needs. Savings account is an account usually is used to save some money for the future, and it may earn some interest depending on your bank", answer2: "A chequing account is where the bank pays you cheques. A savings account is where the bank allows you to withdraw free money", answer3: "A chequing account is not a real account. There are only savings account", correctAnswer: "A chequing account is often used as an account for keeping cash for everyday needs. Savings account is an account usually is used to save some money for the future, and it may earn some interest depending on your bank" },
quest6: { question: "What are Dividends?", answer1: "Dividends are divided stocks that are paid for in the end", answer2: "Money that is owed to you from 10 different people", answer3: "Dividends are cash payments made from the company’s profit, which are paid to shareholders.", correctAnswer: "Dividends are cash payments made from the company’s profit, which are paid to shareholders." },
quest7: { question: "What are mutual funds?", answer1: "It is an actively managed pool of funds and Investors purchase units of the mutual fund.", answer2: "A mutual agreement between the bank and client to always protect hisor her account", answer3: "A type of of savings account that help you become a millionaire", correctAnswer: "It is an actively managed pool of funds and Investors purchase units of the mutual fund." },
quest8: { question: "What is an Exchange traded Fund?", answer1: "A type of foreign exchange fund that helps you convert money faster", answer2: "A liability that you have to pay back to the bank", answer3: "An exchange traded fund is another type of pooled invested that is passively managed.", correctAnswer: "An exchange traded fund is another type of pooled invested that is passively managed." },
quest9: { question: "What is diversification?", answer1: "Investing in a few stocks, bonds, GICS and etc. Instead of putting all your money into one basket, you are putting the funds in several investments.", answer2: "Diversifying your chequing accounts to have lower account fees", answer3: "There is no such thing as diversification. Just put all your money in one stock to get the most money", correctAnswer: "Investing in a few stocks, bonds, GICS and etc. Instead of putting all your money into one basket, you are putting the funds in several investments." },
quest10: { question: "What is a stock?", answer1: "An investment tool that represents part ownership in a company.", answer2: "type of company that you can hold to buy a house or land", answer3: "a type of line of credit to make you a lot of money", correctAnswer: "An investment tool that represents part ownership in a company." },
quest11: { question: "What are hedge funds?", answer1: "A small group of investors who come together to invest money", answer2: "A pooled fund that use complex strategies to gain returns for investors", answer3: "Investors that invest into stocks internationally to gain an edge over other investors", correctAnswer: "A pooled fund that use complex strategies to gain returns for investors" },
}
var clickcount = 1;
var counter = 1;
var questionCounter = "quest" + (counter + 1);
var btn;
var box;
var i = 0;
var Score = 0;
var myVar;
function timerr() {
clickcount--;
clearInterval(myVar)
}
function hideQuestion() {
window.scrollTo(0,document.body.scrollHeight);
if (clickcount < 2) {
clickcount++;
if (counter === 1) { move(); }
box = document.querySelector(`.question${counter}`),
btn = document.querySelector(`#button${counter}`);
if (counter == 10) {
quizzScore();
counter++;
box.classList.add('visuallyhidden');
box.addEventListener('transitionend', function (e) {
box.classList.add('hidden');
}, {
capture: false,
once: true,
passive: false
})
console.log(`counter is ${counter}`)
var test2 = document.querySelector(`.finished`)
test2.innerHTML = `
<h3>Congratulations You Finished !</h3>
<h2> Score: ${Score}</h2>
<div class="input-group mb-6 score-button" >
<button onclick ="saveScore()" class="btn btn-outline-secondary" type="button" id="button-addon1">Submit Your Name</button>
<input type="text" class="form-control" id="scoreName" placeholder="" aria-label="Example text with button addon" aria-describedby="button-addon1">
</div><p id="alert" style="color:white ;width:70%; margin:auto;">Please Write Your Name</p>
`
test2.classList.remove('hidden');
setTimeout(function () {
test2.classList.remove('visuallyhidden');
}, 1000);
myVar = setInterval(timerr, 1000);
} else {
quizzScore();
if (counter === 1) {
box.classList.add('visuallyhidden');
box.addEventListener('transitionend', function (e) {
box.classList.add('hidden');
}, {
capture: false,
once: true,
passive: false
}); counter++;
questionCounter = "quest" + (counter + 1);
var test = document.querySelector(`.question${counter}`)
test.innerHTML = `
<p>${quizzQuestions[questionCounter].question}</p>
<div id="question${counter}">
<input type="radio" id="answer${counter}1" name="answer" value="${quizzQuestions[questionCounter].answer1}">${quizzQuestions[questionCounter].answer1}<br>
<input type="radio" id="answer${counter}2" name="answer" value="${quizzQuestions[questionCounter].answer2}">${quizzQuestions[questionCounter].answer2}<br>
<input type="radio" id="answer${counter}3" name="answer" value="${quizzQuestions[questionCounter].answer3}">${quizzQuestions[questionCounter].answer3}<br><br>
<button onclick="hideQuestion()" id="button${counter}">Submit This Answer</button>
`
test.classList.remove('hidden');
setTimeout(function () {
test.classList.remove('visuallyhidden');
}, 1000); myVar = setInterval(timerr, 1000);
}
else {
if (document.getElementById(`answer${counter}1`).checked || document.getElementById(`answer${counter}2`).checked ||
document.getElementById(`answer${counter}3`).checked) {
box.classList.add('visuallyhidden');
box.addEventListener('transitionend', function (e) {
box.classList.add('hidden');
}, {
capture: false,
once: true,
passive: false
}); counter++;
questionCounter = "quest" + (counter + 1);
var test = document.querySelector(`.question${counter}`)
test.innerHTML = `
<p>${quizzQuestions[questionCounter].question}</p>
<div id="question${counter}">
<input type="radio" id="answer${counter}1" name="answer" value="${quizzQuestions[questionCounter].answer1}">${quizzQuestions[questionCounter].answer1}<br>
<input type="radio" id="answer${counter}2" name="answer" value="${quizzQuestions[questionCounter].answer2}">${quizzQuestions[questionCounter].answer2}<br>
<input type="radio" id="answer${counter}3" name="answer" value="${quizzQuestions[questionCounter].answer3}">${quizzQuestions[questionCounter].answer3}<br><br>
<button onclick="hideQuestion()" id="button${counter}">Submit This Answer</button>
`
test.classList.remove('hidden');
setTimeout(function () {
test.classList.remove('visuallyhidden');
}, 1000); myVar = setInterval(timerr, 1000);
}
else {
document.getElementById("answerOutput").classList.add("wrong");
document.getElementById("answerOutput").innerHTML = "Please choose one of the answer"
myVar = setInterval(timerr, 1000);
}
}
}
}
};
var width;
function move() {
if (i == 0) {
i = 1;
var elem = document.getElementById("myBar");
width = 100;
var id = setInterval(frame, 2000);
function frame() {
if (width <= 0 || counter == 11) {
if (width <= 0) {
box = document.querySelector(`.question${counter}`),
box.classList.add('visuallyhidden');
box.addEventListener('transitionend', function (e) {
box.classList.add('hidden');
}, {
capture: false,
once: true,
passive: false
})
console.log(`counter is ${counter}`)
counter = 11;
var test2 = document.querySelector(`.finished`)
test2.innerHTML = `
<h3>Time IS UP! Hard Luck!</h3>
<h2> Score: ${Score}</h2>
<div class="input-group mb-6 score-button" >
<button onclick ="saveScore()" class="btn btn-outline-secondary" type="button" id="button-addon1">Submit Your Name</button>
<input type="text" class="form-control" id="scoreName" placeholder="" aria-label="Example text with button addon" aria-describedby="button-addon1">
</div><p id="alert" style=" color:white ;width:70%; margin:auto;">Please Write Your Name</p>
`
test2.classList.remove('hidden');
setTimeout(function () {
test2.classList.remove('visuallyhidden');
}, 1000);
}
clearInterval(id);
i = 0;
} else {
width--;
elem.style.width = width + "%";
elem.innerHTML = width + "%";
}
}
}
}
function quizzScore() {
if (counter >= 2) {
for (var i = 1; i < 4; i++) {
var b = document.getElementById(`answer${counter}${i}`)
if (b.checked) {
console.log(b.value)
if (b.value == quizzQuestions[questionCounter].correctAnswer) {
console.log(`${b.value} is a correct answer!`)
if (document.getElementById("answerOutput").classList.contains("wrong")) {
document.getElementById("answerOutput").classList.remove('wrong');
}
document.getElementById("answerOutput").classList.add("correct");
document.getElementById("answerOutput").innerText = `Correct answer! => Score increased by 10 pts`
Score += 10
console.log(Score)
}
else {
document.getElementById("answerOutput").classList.add("wrong");
width = width - 5;
if (document.getElementById("answerOutput").classList.contains("correct")) {
document.getElementById("answerOutput").classList.remove('correct');
}
document.getElementById("answerOutput").innerText = `Wrong answer! => Time decreased by 5 %`
}
}
}
}
}
var justOnce = 1
var testObject = {}
var nbrOfTimes
var arraytest = []
function saveScoreBefore() {
if (justOnce === 1) {
if (localStorage.getItem('arraytest')) {
var retrievedObject = localStorage.getItem('arraytest');
for (var t = 0; t < JSON.parse(retrievedObject).length; t++) {
var theName = JSON.parse(retrievedObject)[t].quiz.name;
var theScore = JSON.parse(retrievedObject)[t].quiz.score;
const li = document.createElement('li')
li.setAttribute('class', 'list-group-item')
li.textContent = `${theName} : ${theScore} pts`
document.getElementById('list-group').appendChild(li)
}
justOnce++
}
}
}
function saveScore() {
if (counter === 11) {
if (document.getElementById("scoreName").value === "") {
document.getElementById("alert").innerText = "Please Write Your Name"
}
else {
var userName = document.getElementById('scoreName').value
if (localStorage.getItem('arraytest')) {
var retrievedObject = localStorage.getItem('arraytest');
arraytest = JSON.parse(retrievedObject)
}
arraytest.push({ 'quiz': { 'name': `${userName}`, 'score': `${Score}` } });
localStorage.setItem('arraytest', JSON.stringify(arraytest));
location.reload();
}
}
}
function clearAll(){
localStorage.clear()
while( document.getElementById('list-group')){
document.getElementById('list-group').remove()
}
}
</script>
</body>
</html>