-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquiz.html
449 lines (402 loc) · 11.2 KB
/
quiz.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
<!DOCTYPE html>
<html>
<style>
@import url(https://fonts.googleapis.com/css?family=Work+Sans:300,600);
body{
font-size: 26px;
font-family: 'Work Sans', sans-serif;
color: #333;
font-weight: 300;
text-align: center;
background-color: #f8f6f0;
}
h1{
font-weight: 300;
margin: 0px;
padding: 10px;
font-size: 35px;
background-color: #444;
color: #fff;
}
.question{
font-size: 30px;
margin-bottom: 10px;
}
.answers {
margin-bottom: 20px;
text-align: left;
display: inline-block;
}
.answers label{
display: block;
margin-bottom: 10px;
transform: ease;
}
button{
font-family: 'Work Sans', sans-serif;
font-size: 22px;
background-color: #7E57C2;
color: #fff;
border: 0px;
border-radius: 10px;
padding: 20px;
cursor: pointer;
margin-bottom: 30px;
margin-top: 150px
}
button:hover{
background-color: #38a;
}
.slide{
position: absolute;
left: 0px;
top: 0px;
width: 100%;
z-index: 1;
opacity: 0;
transition: opacity 0.5s;
}
.active-slide{
opacity: 1;
z-index: 2;
}
.quiz-container{
position: relative;
height: 200px;
margin-top: 40px;
}
/* Beginning of heading video */
.fullscreen {
position: relative;
height: 100%;
overflow: hidden;
}
.fullscreen_video {
min-width: 100%;
overflow: hidden;
z-index: -1;
height: 1000px;
}
.video_overlay_text {
position: absolute;
z-index: 9999;
color: white;
top: 40%;
left: 50%;
transform: translate(-50%,-50%);
}
.dropbtn {
background-color: #555;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropbtn:hover, {
background-color: #2980B9;
}
.dropdown {
position: relative;
}
.dropdown-content {
display: none;
background-color: #555;
min-width: 160px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {background-color: #ddd;}
.show {display: block;}
/* Menu Bar */
.menu-bar {
width: 100%;
background-color: #555;
overflow: auto;
}
.menu-bar a {
float: left;
width: 16.6%;
text-align: center;
padding: 26px 0;
transition: all 0.3s ease;
color: white;
font-size: 26px;
text-decoration:none;
}
.menu-bar a:hover {
background-color: #000;
}
.active {
background-color: #7E57C2
}
</style>
<body>
<!-- Menu Bar -->
<div class="menu-bar">
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/"> Home </a>
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/personal.html"> Personal Life </a>
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/work.html"> Achievements</a>
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/context.html"> Context </a>
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/newMain.html"> Legacy </a>
<div class="dropdown">
<a href="#" onclick="myFunction()" class="dropbtn active"> More </a>
<div id="myDropdown" class="dropdown-content">
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/about.html">About us</a>
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/Marian_Lockwood_Quiz.html" >Lockwood Quiz</a>
<a href="https://hackthesolarsystem.github.io/Marian-Lockwood/quiz.html" class = "active">Space Quiz</a>
</div>
</div>
</div>
<!-- end Menu Bar -->
<div class = "fullscreen">
<div class = "video_overlay_text">
<h1>Quiz on Space Facts</h1>
<div class="quiz-container">
<div id="quiz"></div>
</div>
<button id="previous">Previous Question</button>
<button id="next">Next Question</button>
<button id="submit">Submit Quiz</button>
<div id="results"></div></div>
<video loop muted autoplay poster="img/videoframe.jpg" class = "fullscreen_video">
<source src="Space-2381.mp4" type="video/mp4">
</video>
</div>
<script>
(function() {
const myQuestions = [
{
question: "How many degrees celsius can the core of a star reach?",
answers: {
a: "1,200",
b: "12,000",
c: "120,000",
d: "1,200,000"
},
correctAnswer: "d"
},
{
question: "How old is the universe in billions of years?",
answers: {
a: "14.6",
b: "13.8",
c: "11.7",
d: "10.5"
},
correctAnswer: "b"
},
{
question: "How many planets are in the solar system?",
answers: {
a: "10",
b: "9",
c: "8",
d: "7"
},
correctAnswer: "c"
},
{
question: "What percent of the universe is dark matter?",
answers: {
a: "20%",
b: "24%",
c: "27%",
d: "30%"
},
correctAnswer: "c"
},
{
question: "What are the most common type of stars in the solar system?",
answers: {
a: "Red Dwarfs",
b: "Blue Giants",
c: "Yellow Dwarfs",
d: "Neutron Stars"
},
correctAnswer: "a"
},
{
question: "What is the next closest star to Earth besides the sun?",
answers: {
a: "Alula Australis",
b: "Proxima Centauri",
c: "Polaris Australis",
d: "Nusakan"
},
correctAnswer: "b"
},
{
question: "What is the longest continuous time a human has spent in space??",
answers: {
a: "437 days",
b: "238 days",
c: "563 days",
d: "369 days"
},
correctAnswer: "a"
},
{
question: "How much time does sun rays take to reach earth?",
answers: {
a: "8 minutes",
b: "10 minutes",
c: "15 minutes",
d: "17 minutes"
},
correctAnswer: "a"
},
{
question: "How old is the Earth in billions of years?",
answers: {
a: "2.3",
b: "3.2",
c: "4.5",
d: "5.9"
},
correctAnswer: "c"
},
{
question: "Which is the largest planet in the solar system?",
answers: {
a: "Jupiter",
b: "Earth",
c: "Mars",
d: "Saturn"
},
correctAnswer: "a"
}
];
function buildQuiz() {
// we'll need a place to store the HTML output
const output = [];
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// we'll want to store the list of answer choices
const answers = [];
// and for each available answer...
for (letter in currentQuestion.answers) {
// ...add an HTML radio button
answers.push(
`<label>
<input type="radio" name="question${questionNumber}" value="${letter}">
${letter} :
${currentQuestion.answers[letter]}
</label>`
);
}
// add this question and its answers to the output
output.push(
`<div class = "radio-toolbar">
<div class="slide">
<div class="question"> ${currentQuestion.question} </div>
<div class="answers"> ${answers.join("")} </div>
</div>
</div>`
);
});
// finally combine our output list into one string of HTML and put it on the page
quizContainer.innerHTML = output.join("");
}
function showResults() {
// gather answer containers from our quiz
const answerContainers = quizContainer.querySelectorAll(".answers");
// keep track of user's answers
let numCorrect = 0;
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// find selected answer
const answerContainer = answerContainers[questionNumber];
const selector = `input[name=question${questionNumber}]:checked`;
const userAnswer = (answerContainer.querySelector(selector) || {}).value;
// if answer is correct
if (userAnswer === currentQuestion.correctAnswer) {
// add to the number of correct answers
numCorrect++;
// color the answers green
answerContainers[questionNumber].style.color = "lightgreen";
} else {
// if answer is wrong or blank
// color the answers red
answerContainers[questionNumber].style.color = "red";
}
});
// show number of correct answers out of total
if (numCorrect <= 4) {
resultsContainer.innerHTML = `<h1> ${numCorrect} out of ${myQuestions.length} <br>Don't quit your day job.<h1>`;
} else if (numCorrect <= 6) {
resultsContainer.innerHTML = `<h1> ${numCorrect} out of ${myQuestions.length} <br>Perhaps space is not your strength.<h1>`;
} else if (numCorrect <= 9) {
resultsContainer.innerHTML = `<h1> ${numCorrect} out of ${myQuestions.length} <br>The force is strong with you!<h1>`;
} else {
resultsContainer.innerHTML = `<h1> ${numCorrect} out of ${myQuestions.length} <br>Congratulations! You are the Master of the Universe!<h1>`;
}
}
function showSlide(n) {
slides[currentSlide].classList.remove("active-slide");
slides[n].classList.add("active-slide");
currentSlide = n;
if (currentSlide === 0) {
previousButton.style.display = "none";
} else {
previousButton.style.display = "inline-block";
}
if (currentSlide === slides.length - 1) {
nextButton.style.display = "none";
submitButton.style.display = "inline-block";
} else {
nextButton.style.display = "inline-block";
submitButton.style.display = "none";
}
}
function showNextSlide() {
showSlide(currentSlide + 1);
}
function showPreviousSlide() {
showSlide(currentSlide - 1);
}
const quizContainer = document.getElementById("quiz");
const resultsContainer = document.getElementById("results");
const submitButton = document.getElementById("submit");
// display quiz right away
buildQuiz();
const previousButton = document.getElementById("previous");
const nextButton = document.getElementById("next");
const slides = document.querySelectorAll(".slide");
let currentSlide = 0;
showSlide(0);
// on submit, show results
submitButton.addEventListener("click", showResults);
previousButton.addEventListener("click", showPreviousSlide);
nextButton.addEventListener("click", showNextSlide);
})();
</script>
<script>
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
</body>
</html>