-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
164 lines (132 loc) · 3.79 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
const quizData= [
{
question: 'Easy one to start with : 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 so that 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 when they played the giant game of chess in her first year?',
a: 'Pawn',
b: 'Bishop',
c: 'Castle',
d: 'Knight',
correct: 'c',
},
{
question: 'What is Severus Snapes Patronus Charm?',
a: 'A doe',
b: 'A deer',
c: 'A beaver',
d: 'A snake',
correct: 'a',
},
{
question: 'What was the event in the Triwizard Tournament called which meant that male would dance with female?',
a: 'The Magic Ball',
b: 'The Charm Ball',
c: 'The Triwizard Ball',
d: 'The Yule Ball',
correct: 'd',
},
{
question: "What is Albus Dumbledore's brother called?",
a: 'Arthur',
b: 'Aberforth',
c: 'Aberfol',
d: 'Grindelwald',
correct: 'b',
},
{
question: 'What is the name of the girl ghost who haunts the female bathrooms and who died seeing the Basilisk?',
a: 'Haughty Hetty',
b: 'Scaredy-cat Sara',
c: 'Miserable Myrtle',
d: 'Moaning Myrtle',
correct: 'd',
},
{
question: 'Who murdered Albus Dumbledore?',
a: 'Draco Malfoy',
b: 'Bellatrix Lestrange',
c: 'Severus Snape',
d: 'Salazar Slytherin',
correct: 'c',
},
];
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 currentQuiz = 0;
let score = 0;
function loadQuiz(){
deSelectAnswers();
const currentQuizData = quizData[currentQuiz];
question.innerText = currentQuizData.question;
aText.innerText = currentQuizData.a;
bText.innerText = currentQuizData.b;
cText.innerText = currentQuizData.c;
dText.innerText = currentQuizData.d;
}
loadQuiz();
function deSelectAnswers(){
answers.forEach((answerEl) => {
answerEl.checked = false;
});
}
function getSelected() {
let answer;
answers.forEach((answers) => {
if (answers.checked){
answer = answers.id;
}
});
return answer;
}
const submitBtn = document.getElementById('submitBtn');
submitBtn.addEventListener('click', ()=>{
const answer = getSelected();
if (answer === quizData[currentQuiz].correct){
score++;
}
currentQuiz++;
if (currentQuiz < quizData.length){
loadQuiz();
}
else {
quiz.innerHTML=`
<h1>You answered ${score}/10 questions correctly 🧙🏻♂️</h1>
<button class= "btn green" onclick= 'location.reload()'>Try again</button>
`;
}
});