-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
328 lines (315 loc) · 11 KB
/
script.js
File metadata and controls
328 lines (315 loc) · 11 KB
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
const startButton = document.getElementById('start-btn')
const nextButton = document.getElementById('next-btn')
const questionContainerElement = document.getElementById('question-container')
const questionElement = document.getElementById('question')
const scoreInfo = document.getElementById('score');
const answerButtonsElement = document.getElementById('answer-buttons')
let shuffledQuestions, currentQuestionIndex
let score = 0;
localStorage.setItem('Score', score)
startButton.addEventListener('click', startGame)
nextButton.addEventListener('click', () => {
currentQuestionIndex++
setNextQuestion()
})
function startGame() {
startButton.classList.add('hide')
shuffledQuestions = questions.sort(() => Math.random() - .5)
currentQuestionIndex = 0
questionContainerElement.classList.remove('hide')
setNextQuestion()
}
function disappear(){
let x = document.getElementById('svgHead')
if (x.style.display === 'none'){
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
function setNextQuestion() {
resetState()
showQuestion(shuffledQuestions[currentQuestionIndex])
}
function showQuestion(question) {
questionElement.innerText = question.question
question.answers.forEach(answer => {
const button = document.createElement('button')
button.innerText = answer.text
button.classList.add('btn')
if (answer.correct) {
button.dataset.correct = answer.correct
}
button.addEventListener('click', selectAnswer)
answerButtonsElement.appendChild(button)
})
}
function resetState() {
clearStatusClass(document.body)
nextButton.classList.add('hide')
while (answerButtonsElement.firstChild) {
answerButtonsElement.removeChild(answerButtonsElement.firstChild)
}
}
function selectAnswer(e) {
const selectedButton = e.target
const correct = selectedButton.dataset.correct
setStatusClass(document.body, correct)
Array.from(answerButtonsElement.children).forEach(button => {
setStatusClass(button, button.dataset.correct)
})
if (shuffledQuestions.length > currentQuestionIndex + 1) {
nextButton.classList.remove('hide')
} else {
startButton.innerText = 'Restart'
startButton.classList.remove('hide')
}
}
function setStatusClass(element, correct) {
clearStatusClass(element)
if (correct) {
element.classList.add('correct')
} else {
element.classList.add('wrong')
}
}
function clearStatusClass(element) {
element.classList.remove('correct')
element.classList.remove('wrong')
}
setScore = numb => {
score += numb;
scoreInfo.innerText = score;
localStorage.setItem('Score', score);
}
const questions = [
{
question: 'Who is the favourite player of the developer of this quiz?',
answers: [
{ text: 'Damian Lillard', correct: true },
{ text: 'Stephen Curry', correct: false },
{ text: 'LeBron James', correct: false },
{ text: 'Paul George', correct: false },
// { text: '82 points', correct: false }
]
},
{
question: 'What team did Kobe Bryant retire with?',
answers: [
{ text: 'Chicago Bulls', correct: false },
{ text: 'Charlotte Hornets', correct: false },
{ text: 'Los Angeles Clippers', correct: false },
{ text: 'Los Angeles Lakers', correct: true }
]
},
{
question: 'Which legend is on the NBA official logo',
answers: [
// { text: 'John Stockton', correct: false },
{ text: "Shaq O'Neil", correct: false},
{ text: 'Jerry West', correct: true },
{ text: 'Bill Russell', correct: false },
{text: 'Derrick Jones Jr.', correct: false}
]
},
{
question: 'Which movie did Michael Jordan appear in?',
answers: [
// { text: 'John Stockton', correct: false },
{ text: "Thunderstruck", correct: false},
{ text: 'Like Mike', correct: false},
{ text: 'Space Jam', correct: true },
{text: 'Train Wreck', correct: false}
]
},
{
question: 'Which player scored 8 points in 9 seconds to defeat the Knicks in a playoff game?',
answers: [
// { text: 'John Stockton', correct: false },
{ text: "Clyde Drexler", correct: false},
{ text: 'Reggie Miller', correct: true },
{ text: 'Scottie Pippen', correct: false },
{text: 'Jalen Rose', correct: false}
]
},
{
question: 'Which of these players played for the Warriors',
answers: [
// { text: 'John Stockton', correct: false },
{ text: "DeMarcus Cousins", correct: true },
{ text: 'Anthony Davis', correct: false },
{ text: 'Julius Randle', correct: false },
{text: 'Myles Turner', correct: false}
]
},
{
question: 'How many points did Wilt Chamberlain score in an NBA all-time record?',
answers: [
{ text: '70 points', correct: false },
{ text: '85', correct: false },
{ text: '102', correct: false },
{ text: '100', correct: true },
// { text: '82 points', correct: false }
]
},
{
question: 'Which player has won multiple sixth man of the year awards?',
answers: [
{ text: 'Montrezl Harrell', correct: false },
{ text: 'Eric Gordon', correct: false },
{ text: 'Spencer Dinwiddie', correct: false },
{ text: 'Lou Williams', correct: true },
// { text: '82 points', correct: false }
]
},
{
question: 'Which team drafted Karl-Anthony Towns',
answers: [
{ text: 'Chicago Bulls', correct: false },
{ text: 'Minnesota Tiberwolves', correct: true },
{ text: 'New Orleans Pelicans', correct: false },
{ text: 'Cleveland Cavaliers', correct: false },
// { text: '82 points', correct: false }
]
},
{
question: 'What team did Kevin Garnet retire with?',
answers: [
{ text: 'Brooklyn Nets', correct: false },
{ text: 'Boston Celtics', correct: false },
{ text: 'Los Angeles Clippers', correct: false },
{ text: 'Minnesota Timberwolves', correct: true },
// { text: '82 points', correct: false }
]
},
{
question: 'What college did Anthony Davis play for?',
answers: [
{ text: 'Kentucky', correct: true },
{ text: 'North Carolina', correct: false },
{ text: 'Duke', correct: false },
{ text: 'Michigan St.', correct: false },
// { text: '82 points', correct: false }
]
},
{
question: 'Which team did Paul Pierce retire with?',
answers: [
{ text: 'Brooklyn Nets', correct: false },
{ text: 'Washington Wizards', correct: false },
{ text: 'Boston Celtics', correct: true },
{ text: 'Los Angeles Clippers', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which of these players played for the Raptors?',
answers: [
{ text: 'Jason Terry', correct: false },
{ text: 'Richard Jefferson', correct: false },
{ text: 'Allen Iverson', correct: false },
{ text: 'Vince Carter', correct: true },
// { text: 'The Monster', correct: false }
]
},
{
question: 'How many teams currently play in New York?',
answers: [
{ text: '1', correct: false },
{ text: '2', correct: true },
{ text: '3', correct: false },
{ text: '4', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which team has NEVER won an NBA Championship?',
answers: [
{ text: 'Detroit Pistons', correct: false },
{ text: 'Orlando Magic', correct: true },
{ text: 'Houston Rockets', correct: false },
{ text: 'Dallas Mavericks', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'What is the nickname of Vince Carter?',
answers: [
{ text: 'Vinsanity', correct: true },
{ text: 'Chocolate Thunder', correct: false },
{ text: 'Uncle Drew', correct: false },
{ text: 'The Dream', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which of these players played for the Bucks?',
answers: [
{ text: 'Rajon Rondo', correct: false },
{ text: 'Ray Allen', correct: true },
{ text: 'Kevin Garnett', correct: false },
{ text: 'James Harden', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which position did Charles Barkley play?',
answers: [
{ text: 'PG', correct: false },
{ text: 'SG', correct: false },
{ text: 'SF', correct: false },
{ text: 'PF', correct: true },
// { text: 'The Monster', correct: false }
]
},
{
question: "Which team did Shaquille O'Neal retire with?",
answers: [
{ text: 'Los Angeles Lakers', correct: false },
{ text: 'Boston Celtics', correct: true },
{ text: 'Miami Heat', correct: false },
{ text: 'Phoenix Suns', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'What is the nickname of Dwyane Wade?',
answers: [
{ text: 'Flash', correct: true },
{ text: 'The Mailman', correct: false },
{ text: 'The Answer', correct: false },
{ text: 'Superman', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which player is a former Slam Dunk Contest winner?',
answers: [
{ text: 'Allen Iverson', correct: false },
{ text: "Shaquille O'Neil", correct: false },
{ text: 'Gary Payton', correct: false },
{ text: 'Micheal Jordan', correct: true },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which of these players played for the Knicks?',
answers: [
{ text: 'Carmelo Anthony', correct: true },
{ text: 'Vince Carter', correct: false },
{ text: 'Allen Iverson', correct: false },
{ text: 'Paul Pierce', correct: false },
// { text: 'The Monster', correct: false }
]
},
{
question: 'Which of these players played for the Lakers?',
answers: [
{ text: 'Micheal Jordan', correct: false },
{ text: 'Hakeem Olajuwon', correct: false },
{ text: 'Larry Bird', correct: false },
{ text: 'Magic Johnson', correct: true },
// { text: 'The Monster', correct: false }
]
}
]