-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.js
More file actions
292 lines (277 loc) · 8.05 KB
/
game.js
File metadata and controls
292 lines (277 loc) · 8.05 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
const userStart = () => {
alert('Select a clue by clicking on any point value. Point values indicate level of difficulty')
}
const letsPlay = document.querySelector('#letsPlay')
let userScore1 = document.querySelector('#p1Score')
let userScore2 = document.querySelector('#p2Score')
let player1Score = 0
let player2Score = 0
let player1Turn = true
let player2Turn = false
let answeredQuestionsCount = 0;
let btnList = []
let btnIDs = [
'#elves100',
'#dwarves100',
'#hobbits100',
'#books100',
'#locations100',
'#potpourri100',
'#elves200',
'#dwarves200',
'#hobbits200',
'#books200',
'#locations200',
'#potpourri200',
'#elves300',
'#dwarves300',
'#hobbits300',
'#books300',
'#locations300',
'#potpourri300',
'#elves400',
'#dwarves400',
'#hobbits400',
'#books400',
'#locations400',
'#potpourri400',
'#elves500',
'#dwarves500',
'#hobbits500',
'#books500',
'#locations500',
'#potpourri500'
]
let questions = [
{
title: 'Elves for 100',
question: 'This elf was the daughter of Elrond',
answer: 'arwen',
points: 100,
},
{
title: 'Dwarves for 100',
question: 'Gimli was the son of this Dwarf',
answer: 'gloin',
points: 100,
},
{
title: 'Hobbits for 100',
question: 'This hobbit carried the One Ring to Mount Doom in order to destroy it',
answer: 'frodo',
points: 100,
},
{
title: 'Books for 100',
question: 'In the novel "The Fellowship of the Ring" this book depicts the celebration of Bilbo\'s eleventy first birthday',
answer: 'the first journey',
points: 100,
},
{
title: 'Locations for 100',
question: 'The Battle of the Hornburg took place in the valley of this location',
answer: 'helm\'s deep',
points: 100,
},
{
title: 'Potpourri for 100',
question: 'One Ring to rule them all, One Ring to find them, One Ring to bring them all an in the darkness `this`',
answer: 'bind them',
points: 100,
},
{
title: 'Elves for 200',
question: 'Elves sailed this direction to reach the Undying Lands',
answer: 'west',
points: 200,
},
{
title: 'Dwarves for 200',
question: 'This precious metal was highly coveted by the Dwarves of Moria',
answer: 'mithril',
points: 200,
},
{
title: 'Hobbits for 200',
question: 'This was the name of Bilbo Baggins literary work',
answer: 'there and back again',
points: 200,
},
{
title: 'Books for 200',
question: 'In this book the two Hobbits Merry and Pippin meet the Ent known as Treebeard',
answer: 'the treason of isengard',
points: 200,
},
{
title: 'Locations for 200',
question: 'The fortress of Isengard was located at the southern tip of this mountain range',
answer: 'misty mountains',
points: 200,
},
{
title: 'Potpourri for 200',
question: 'Elesar ',
answer: 'isildur',
points: 200,
},
{
title: 'Elves for 300',
question: 'Legolas hailed from this Elven realm',
answer: 'mirkwood',
points: 300,
},
{
title: 'Dwarves for 300',
question: 'This is how many Rings of Power that were given to the Dwarves',
answer: '7',
points: 300,
},
{
title: 'Hobbits for 300',
question: 'The longest living Hobbit was Bilbo Baggins who lived to this age',
answer: '131',
points: 300,
},
{
title: 'Books for 300',
question: 'This book shares the same name as the novel in which it is found',
answer: 'the return of the king',
points: 300,
},
{
title: 'Locations for 300',
question: 'The creatures known as Ents inhabitied this forest',
answer: 'fangorn forest',
points: 300,
},
{
title: 'Potpourri for 300',
question: 'In two songs from 1971: "Misty Mountain Hop" and "The Battle of Evermore" this band referenced the works of Tolkien',
answer: 'led zeppelin',
points: 300,
},
{
title: 'Elves for 400',
question: 'This elf was the only elf not to be given one of the Three Rings of power',
answer: 'elrond',
points: 400,
},
{
title: 'Dwarves for 400',
question: 'This sword was weilded by Thorin II `Oakensheild` in the novel The Hobbit, also known as the Goblin-cleaver',
answer: 'orcrist',
points: 400,
},
{
title: 'Hobbits for 400',
question: 'Frodo Baggins was the son of this Hobbit',
answer: 'drogo',
points: 400,
},
{
title: 'Books for 400',
question: 'The story "Of Beren and Luthien are contained in this book',
answer: 'the silmarillion',
points: 400,
},
{
title: 'Locations for 400',
question: 'Lady Arwen crossed this river to save Frodo as she escaped the Nazgul',
answer: 'the bruinen',
points: 400,
},
{
title: 'Potpourri for 400',
question: 'The first film adaptation of The Hobbit was released in this year',
answer: '1977',
points: 400,
},
{
title: 'Elves for 500',
question: 'Galadriel was of the Wood-elves who were lesser known as these type of elves',
answer: 'silvan',
points: 500,
},
{
title: 'Dwarves for 500',
question: 'Thorin II was son of this Dwarf',
answer: 'thrain ii',
points: 500,
},
{
title: 'Hobbits for 500',
question: 'Hobbit holes were known as these',
answer: 'smials',
points: 500,
},
{
title: 'Books for 500',
question: 'This was the very first book J.R.R. Tokien began in 1918 but wasn\'t published until after his death in 2007',
answer: 'the children of hurin',
points: 500,
},
{
title: 'Locations for 500',
question: 'The Shire was located in this region of Middle-Earth',
answer: 'eriador',
points: 500,
},
{
title: 'Potpourri for 500',
question: 'Once he held the title of High-captain this Lord of Balrogs was responsible for killing two of the High Kings of the Noldor',
answer: 'gothmog',
points: 500,
},
]
for (let i = 0; i < btnIDs.length; i++) {
btnList.push(document.querySelector(btnIDs[i]));
}
for (let i = 0; i < btnList.length; i++) {
btnList[i].addEventListener('click', (evt) => {
let userAnswer = prompt(questions[i].question)
while (userAnswer === null) {
userAnswer = prompt(questions[i].question);
}
if (userAnswer.toLowerCase() === questions[i].answer) {
if (player1Turn === true) {
player1Score += questions[i].points;
userScore1.innerHTML = player1Score;
}
if (player2Turn === true) {
player2Score += questions[i].points
userScore2.innerHTML = player2Score
}
}
togglePlayerTurn();
evt.target.classList.add('hideButton');
answeredQuestionsCount += 1;
let allQuestionsAnswered = false;
if (answeredQuestionsCount === 30) {
allQuestionsAnswered = true;
} else {
allQuestionsAnswered = false;
}
if (allQuestionsAnswered === true) {
if (player1Score === player2Score) {
alert("DRAW!")
} else if (player1Score > player2Score) {
alert('Player 1 WINS!')
} else {
alert('Player 2 WINS!')
}
}
});
}
const togglePlayerTurn = () => {
if (player1Turn === true) {
player1Turn = false;
player2Turn = true;
} else {
player2Turn = false;
player1Turn = true;
}
}
letsPlay.addEventListener('click', goToGame)
goToGame = () => {
}