-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
338 lines (291 loc) · 7.87 KB
/
index.js
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
const quizData = [
{
question:
"Which house did Ronald Weasley get placed in?",
a: "Ravenclaw",
b: "Slytherin",
c: "Gryffindor",
d: "Hufflepuff",
correct: "c",
},
{
question: 'What does the "Obliviate" spell mean?',
a: "Remove ones memory",
b: "Protect yourself from Dark Magic",
c: "Transform into somebody else",
d: "Transport from one place to another",
correct: "a",
},
{
question: "Who killed Sirius Black before he fell into the Veil?",
a: "Lucius Malfoy",
b: "Lord Voldemort",
c: "Draco Malfoy",
d: "Bellatrix Lestrange",
correct: "d",
},
{
question:
"How many turns did Harry and Hermione require to go back in time with the Time Turner?",
a: "10 turns",
b: "3 turns",
c: "17 turns",
d: "1 turn",
correct: "b",
},
{
question:
"Which position did Hermione Granger play in the giant game of chess in her first year?",
a: "Pawn",
b: "Bishop",
c: "Castle",
d: "Knight",
correct: "c",
},
{
question: "What is Severus Snape's Patronus?",
a: "A doe",
b: "A deer",
c: "A beaver",
d: "A snake",
correct: "a",
},
{
question:
"What was the name of event in the Triwizard Tournament in which students would dance with their partners?",
a: "The Magic Ball",
b: "The Charm Ball",
c: "The Triwizard Ball",
d: "The Yule Ball",
correct: "d",
},
{
question: "What was the name of Albus Dumbledore's brother?",
a: "Arthur",
b: "Abeforth",
c: "Ariana",
d: "Grindelwald",
correct: "b",
},
{
question:
"What is the name of the girl ghost who haunts the female bathrooms and died seeing the Basilisk?",
a: "Haughty Hetty",
b: "Scaredy-cat Sara",
c: "Miserable Myrtle",
d: "Moaning Myrtle",
correct: "d",
},
{
question: "Who killed Albus Dumbledore?",
a: "Draco Malfoy",
b: "Bellatrix Lestrange",
c: "Severus Snape",
d: "Salazar Slytherin",
correct: "c",
},
{
question: "When Dumbledore collected Harry from the Dursleys, what drink did he give them?",
a: "Butterbeer",
b: "Firewhisky",
c: "Oak-matured mead",
d: "Pumpkin juice",
correct: "c",
},
{
question: "What was the name of only book that Hermoine could find that mentioned Horcruxes?",
a: "Secrets of the Darkest Arts",
b: "Magick Moste Evile",
c: "Moste Potente Potions",
d: "Olde and Forgotten Bewitchments and Charms",
correct: "b",
},
{
question: "What was the name of the Department of Magical Law Enforcement employee whose memory Harry saw in the Pensieve?",
a: "Bob Ogden",
b: "Bertram Oakden",
c: "Jasper Ocken",
d: "Colin Ogilvy",
correct: "a",
},
{
question: "A poster for what product was displayed in the window of Weasleys' Wizard Wheezes?",
a: "Skiving Snackboxes",
b: "U-No-Poo",
c: "Decoy Detonator",
d: "Pygmy Puffs",
correct: "b",
},
{
question: "What was the name of Severus Snape's mother?",
a: "Eliza Hinch",
b: "Elsie King",
c: "Eileen Prince",
d: "Ellen Finch",
correct: "c",
},
{
question: "What was Lavender Brown's nickname for Ron?",
a: "My Wonnykins",
b: "Little Wonkins",
c: "Wonny",
d: "Won-Won",
correct: "d",
},
{
question: "Who was the matron at the orphanage that Tom Riddle grew up in?",
a: "Mrs. Cole",
b: "Ms. Tomkins",
c: "Miss Babbage",
d: "Mrs. Jones",
correct: "a",
},
{
question: "What were the initials of the person who had stolen the real Horcrux from the cave?",
a: "S.B.",
b: "H.J.P.",
c: "R.A.B.",
d: "A.P.W.B.D.",
correct: "c",
},
{
question: "What was the name of Barty Crouch's house-elf?",
a: "Dobby",
b: "Hokey",
c: "Kreacher",
d: "Winky",
correct: "d",
},
{
question: "What creature did Barty Crouch Jr. posing as Professor Moody turn Draco into?",
a: "Rat",
b: "Ferret",
c: "Weasel",
d: "Vole",
correct: "b",
},
{
question: "What was the name of the Riddle family's gardener who was murdered?",
a: "Reggie Wilson",
b: "Gary Green",
c: "Frank Bryce",
d: "Colin Brown",
correct: "c",
},
{
question: "What did Hermione discover Rita Skeeter's unregistered Animagus form was?",
a: "Ladybird",
b: "Beetle",
c: "Cockroach",
d: "Butterfly",
correct: "b",
},
{
question: "What was the answer to the Sphinx's riddle that Harry had to answer in the third task?",
a: "Lion",
b: "Time",
c: "Circle",
d: "Spider",
correct: "d",
},
{
question: "What item of clothing did Dobby receive which set him free?",
a: "Sock",
b: "Wooly Jumper",
c: "Scarf",
d: "Hat",
correct: "a",
},
];
const quiz = document.getElementById("Quiz");
const answers = document.querySelectorAll(".answer");
const question = document.querySelector("#question");
const aText = document.getElementById("aText");
const bText = document.getElementById("bText");
const cText = document.getElementById("cText");
const dText = document.getElementById("dText");
let tempArray = Array;
let currentQuiz = 0;
let score = 0;
function shuffleQuestions() {
let currentIndex = quizData.length, randomIndex;
while (currentIndex != 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[quizData[currentIndex], quizData[randomIndex]] = [quizData[randomIndex], quizData[currentIndex]];
}
}
function shuffleAnswers(array) {
let currentIndex = array.length, randomIndex;
while (currentIndex != 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
}
return array;
}
shuffleQuestions();
function loadQuiz() {
deSelectAnswers();
const currentQuizData = quizData[currentQuiz];
question.innerText = currentQuizData.question;
tempArray = shuffleAnswers([currentQuizData.a, currentQuizData.b, currentQuizData.c, currentQuizData.d])
aText.innerText = tempArray[0];
bText.innerText = tempArray[1];
cText.innerText = tempArray[2];
dText.innerText = tempArray[3];
}
loadQuiz();
function deSelectAnswers() {
answers.forEach((answerEl) => {
answerEl.checked = false;
});
}
function getSelected() {
let answer = "";
answers.forEach((answers) => {
if (answers.checked) {
if (answers.id === "a") {
answer = tempArray[0];
}
else if (answers.id === "b") {
answer = tempArray[1];
}
else if (answers.id === "c") {
answer = tempArray[2];
}
else if (answers.id === "d") {
answer = tempArray[3];
}
}
});
return answer;
}
const submitBtn = document.getElementById("submitBtn");
submitBtn.addEventListener("click", () => {
const answer = getSelected();
if (answer === quizData[currentQuiz][quizData[currentQuiz].correct]) {
score++;
}
currentQuiz++;
if (currentQuiz < quizData.length) {
if (answer.length == 0) {
alert("Please Select your answer");
currentQuiz--;
}
loadQuiz();
nextQuestion();
} else {
document.querySelector('body').style.backgroundImage='url(https://i.pinimg.com/736x/b2/d1/ae/b2d1ae4368c810255c2fecf82dba77c9.jpg)'
quiz.innerHTML = `
<h1>You answered ${score}/24 questions correctly 🧙🏻♂️</h1>
<button class= "btn green" onclick= 'location.reload()'>Try again</button>
`;
}
});
function nextQuestion() {
var elem = document.getElementById("bar");
var width = 24 * (currentQuiz+1);
elem.style.width = width + "%";
elem.innerHTML = width + "%";
}