-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
429 lines (405 loc) · 13.9 KB
/
Copy pathscript.js
File metadata and controls
429 lines (405 loc) · 13.9 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
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
// an object literal will store the trivia questions and their answers.
const triviaQuestions = [
{
question:
"Which great American novel was a tremendous failure upon its publication?",
answers: {
a: {
title: "Where the Red Fern Grows by Wilson Rawls",
url: "./images/wheretheredferngrows.jpg",
correct: false,
},
b: {
title: "The Great Gatsby by F Scott Fitzgerald",
url: "./images/greatgatsby.jpg",
correct: true,
},
c: {
title: "Frankenstein by Mary Shelley",
url: "./images/frankenstein.jpg",
correct: false,
},
d: {
title: "Fahrenheit 451 by Ray Bradbury",
url: "./images/fahrenheit451.jpg",
correct: false,
},
bonusTrivia:
"F. Scott Fitzgerald had experienced much success before its publication, but The Great Gatsby was poorly received. He died thinking himself a failure, mostly forgotten. School curricula sparked renewed interest in it around WWII and today, it is its publishing house's highest-selling title.",
},
},
{
question:
"According to a study conducted by the New York Public Library this year, which of the following books is its most regularly borrowed?",
answers: {
a: {
title: "The Very Hungry Caterpillar by Eric Carle",
url: "./images/veryhungrycaterpillar.jpg",
correct: false,
},
b: {
title: "Goodnight Moon by Margaret Wise Brown",
url: "./images/goodnightmoon.jpg",
correct: false,
},
c: {
title: "The Snowy Day by Ezra Jack Keats",
url: "./images/snowyday.jpg",
correct: true,
},
d: {
title: "Harry Potter and the Sorcerer's Stone by JK Rowling",
url: "./images/harrypottersorcerersstone.jpg",
correct: true,
},
bonusTrivia:
"In addition to being the most frequently borrowed book from the NYPL, The Snowy Day was the first picture book to portray a Black child positively: simply being a child.",
},
},
{
question:
"Which of the following beloved authors was the first Black American to win the Nobel Prize in Literature?",
answers: {
a: {
title: "Toni Morrison",
url: "./images/tonimorrison.jpg",
correct: true,
},
b: {
title: "James Baldwin",
url: "./images/jamesbaldwin.jpeg",
correct: false,
},
c: {
title: "Maya Angelou",
url: "./images/mayaangelou.png",
correct: false,
},
d: {
title: "Langston Hughes",
url: "./images/langstonhughes.jpg",
correct: false,
},
bonusTrivia:
"Toni Morrison published her first novel, The Bluest Eye, when she was 39 years old. She was the first Black woman of any nationality to win the Nobel Prize in literature.",
},
},
{
question:
"Which of the following books was penned when its author was only 16 years old?",
answers: {
a: {
title: "Normal People by Sally Rooney",
url: "./images/normalpeople.jpg",
correct: false,
},
b: {
title: "Sisterhood of the Traveling Pants by Ann Brashares",
url: "./images/sisterhoodofthetravelingpants.jpg",
correct: false,
},
c: {
title: "The Outsiders by SE Hinton",
url: "./images/theoutsiders.jpg",
correct: true,
},
d: {
title: "The Awakening by Kate Chopin",
url: "./images/theawakening.jpeg",
correct: false,
},
bonusTrivia:
"Hinton was 15 when she started writing the novel, 16 when she wrote the bulk of it, and 18 when it was actually published. It is widely regarded as the first YA novel, written specifically for a teenage audience.",
},
},
{
question: "What was 2018’s highest selling book in the US?",
answers: {
a: {
title: "Becoming by Michelle Obama",
url: "./images/becoming.jpg",
correct: true,
},
b: {
title: "A Higher Loyalty by James Comey",
url: "./images/higherloyalty.jpg",
correct: false,
},
c: {
title: "Fear: Trump in the White House",
url: "./images/fear.jpg",
correct: false,
},
d: {
title: "The Mueller Report",
url: "./images/muellerreport.jpg",
correct: false,
},
bonusTrivia:
"Michelle Obama's 'Becoming' broke the record for most books sold in 2018 in just 15 days. Questlove curated a soundtrack for the book, called The Michelle Obama Musiaqualogy.",
},
},
{
question: "Which of the following books is the most commonly stolen?",
answers: {
a: {
title: "Steal This Book by Abbie Hoffman",
url: "./images/stealthisbook.jpg",
correct: false,
},
b: {
title: "The Bible",
url: "./images/bible.jpg",
correct: true,
},
c: {
title: "The Catcher in the Rye by JD Salinger",
url: "./images/catcherintherye.jpg",
correct: false,
},
d: {
title: "The Communist Manifesto by Karl Marx & Frederick Engels",
url: "./images/communist manifesto.jpg",
correct: false,
},
bonusTrivia:
"In spite of the commandment wherein thou art forbidden from stealing, The Bible is the most commonly stolen book. (While The Catcher in the Rye is not one of the most commonly shoplifted titles, it has been associated with many high-profile assassinations, including that of President John F Kennedy and John Lennon. It's believed that this is why Salinger retreated into solitude for the last four decades of his life.)",
},
},
{
question:
"Which of the following books was used as evidence against its author in a trial persecuting that author for homosexuality?",
answers: {
a: {
title: "Where the Wild Things Are by Maurice Sendak",
url: "./images/wherethewildthingsare.jpg",
correct: false,
},
b: {
title: "The Picture of Dorian Gray by Oscar Wilde",
url: "./images/pictureofdoriangray.jpg",
correct: true,
},
c: {
title: "In Cold Blood by Truman Capote",
url: "./images/incoldblood.jpg",
correct: false,
},
d: {
title: "Giovanni's Room by James Baldwin",
url: "./images/giovannisroom.jpg",
correct: false,
},
bonusTrivia:
"Oscar Wilde was eventually sent to prison for indecency, where he continued writing. (While James Baldwin was never persecuted for his sexuality, the FBI did compile almost two thousand pages of surveillance on Baldwin.)",
},
},
{
question:
"Which of the following authors was the first—-and to date, the only—-person to become a billionaire strictly by writing books?",
answers: {
a: {
title: "JK Rowling",
url: "./images/JKRowling.jpg",
correct: true,
},
b: {
title: "Stephen King",
url: "./images/stephenking.jpg",
correct: false,
},
c: {
title: "Agatha Christie",
url: "./images/agathachristie.jpg",
correct: false,
},
d: {
title: "David Foster Wallace",
url: "./images/dfw.jpeg",
correct: false,
},
bonusTrivia:
"JK Rowling has actually been demoted to millionaire status for donating a significant portion of her earnings to charity.",
},
},
{
question:
"Which of the following books was translated into English (i.e. originally written in a language other than English)?",
answers: {
a: {
title: "Lolita by Vladimir Nabokov",
url: "./images/lolita.jpg",
correct: false,
},
b: {
title: "One Hundred Years of Solitude by Gabriel Garcia Marquez",
url: "./images/onehudnredyears.jpg",
correct: true,
},
c: {
title: "The Goldfinch",
url: "./images/goldfinch.jpg",
correct: false,
},
d: {
title: "All the Light We Cannot See by Anthony Doerr",
url: "./images/allthelightwecannotsee.jpg",
correct: false,
},
bonusTrivia:
"Gabriel Garcia Marquez's One Hundred Years of Solitude is the highest-selling and most-frequenly translated book. It boasts one of literature's most famous first lines: 'Many years later, as he faced the firing squad, Colonel Aureliano Buendia was to remember that distant afternoon when his father took him to discover ice.'",
},
},
{
question:
"Which of the following books was not written by an author after that author served in the armed forces?",
answers: {
a: {
title: "Winnie the Pooh by AA Milne",
url: "./images/winniethepooh.jpg",
correct: false,
},
b: {
title: "Redeployment by Phil Klay",
url: "./images/redeployment.jpg",
correct: false,
},
c: {
title: "Catcher in the Rye by JD Salinger",
url: "./images/catcherintherye.jpg",
correct: false,
},
d: {
title: "The Art of the Deal by Donald Trump",
url: "./images/artofthedeal.jpg",
correct: true,
},
bonusTrivia:
"After returning from fighting in WWI, AA Milne sought to write a book that would end every war forever. Phil Klay's Redeployment won the 2014 National Book Award in Fiction. JD Salinger carried the first few chapters of Catcher in the Rye on him as an amulet when he landed on the beaches of Normandy on D-Day.",
},
},
{
question: "All done!",
answers: {
a: {},
b: {},
c: {},
d: {},
bonusTrivia: "Find your next great read at the links up top.",
},
},
];
//basic structure!
let board = document.querySelector(".board");
let questionContainer = document.querySelector(".question");
//all your buttons!
let submitButton = document.querySelector("#submit");
let choiceA = document.querySelector(".a");
let choiceB = document.querySelector(".b");
let choiceC = document.querySelector(".c");
let choiceD = document.querySelector(".d");
let previousButton = document.querySelector(".previous");
let nextButton = document.querySelector(".next");
let homeButton = document.querySelector(".home");
let a = document.querySelector(".a");
let b = document.querySelector(".b");
let c = document.querySelector(".c");
let d = document.querySelector(".d");
let bonus = document.querySelector(".bonus");
let count = 0; //keeps track of what question to display.
let tally = []; //keeps track of user score.
//button functionalities
homeButton.addEventListener("click", beginGame);
nextButton.addEventListener("click", next);
function beginGame(e) {
e.preventDefault;
count = 0;
tally = [];
next(e);
nextButton.removeEventListener("click", beginGame);
nextButton.addEventListener("click", next);
}
function finish() {
//invokes end of game, prints score.
bq = triviaQuestions[10].answers.bonusTrivia;
if (count == 10) {
a.style.display = "none";
b.style.display = "none";
c.style.display = "none";
d.style.display = "none";
nextButton.innerHTML = "Restart";
nextButton.addEventListener("click", beginGame);
if (tally.length >= 8) {
console.log("hi");
bonus.innerHTML = `Your score is ${tally.length}/10. Good work! ${bq}`;
} else if (5 <= tally.length <= 7) {
console.log("hi");
bonus.innerHTML = `Your score is ${tally.length}/10. Not bad! ${bq}`;
} else if (tally.length < 5) {
console.log("hi");
bonus.innerHTML = `Your score is ${tally.length}/10. Not too hot, but the world is yours for the reading. ${bq}`;
}
}
}
function next(e) {
//prints out every question & option
console.dir(e);
nextButton.innerHTML = "Next";
nextButton.removeEventListener("click", next);
a.style.display = "block";
b.style.display = "block";
c.style.display = "block";
d.style.display = "block";
e.preventDefault;
console.log("next question");
bonus.innerHTML = "";
questionContainer.innerHTML = triviaQuestions[count].question;
a.setAttribute("src", triviaQuestions[count].answers.a.url);
a.setAttribute("data-check", triviaQuestions[count].answers.a.correct);
a.alt = triviaQuestions[count].answers.a.title;
b.setAttribute("src", triviaQuestions[count].answers.b.url);
b.setAttribute("data-check", triviaQuestions[count].answers.b.correct);
b.alt = triviaQuestions[count].answers.b.title;
c.setAttribute("src", triviaQuestions[count].answers.c.url);
c.setAttribute("data-check", triviaQuestions[count].answers.c.correct);
c.alt = triviaQuestions[count].answers.c.title;
d.setAttribute("src", triviaQuestions[count].answers.d.url);
d.setAttribute("data-check", triviaQuestions[count].answers.d.correct);
d.alt = triviaQuestions[count].answers.d.title;
a.addEventListener("click", checkIfCorrect);
b.addEventListener("click", checkIfCorrect);
c.addEventListener("click", checkIfCorrect);
d.addEventListener("click", checkIfCorrect);
finish();
}
// let images = document.getElementsByTagName("img");
// for (let i = 0; i < images.length; i++) {
// images[i].addEventListener('mouseover',show);
// }
// function show(e){
// e.preventDefault;
// let alt = this.alt;
// console.dir(e);
// images.innerHTML = e.target.alt;
// }
function checkIfCorrect(e) {
e.preventDefault;
nextButton.addEventListener("click", next);
a.removeEventListener("click", checkIfCorrect);
b.removeEventListener("click", checkIfCorrect);
c.removeEventListener("click", checkIfCorrect);
d.removeEventListener("click", checkIfCorrect);
console.log(e.target.className);
bq = triviaQuestions[count].answers.bonusTrivia;
if (e.target.dataset.check === "true") {
tally.push(count);
bonus.innerHTML = `Nicely done! ${bq}`;
} else {
bonus.innerHTML = `No dice! ${bq}`;
}
if (count < triviaQuestions.length) {
count++;
} else {
console.log("finished");
}
}