-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjss
330 lines (255 loc) · 7.73 KB
/
jss
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
jQuery(document).ready(function() {
//questions,choices and answers all contained in an array
var ironThrone = [
{
question: 'What does "Valar Morghulis" mean?',
choices: ['Fire and Blood', 'Winter is coming', 'Anyone may die', 'All men must die', ],
correctAnswer: 4
},
{
question: 'Who killed Rhaegar Targaryen?',
choices: ['Ned Stark', 'Jamie Lannister', 'Robert Bartheon', 'Khal Drogo'],
correctAnswer: 3
},
{
question: 'Which of the seven kingdoms has never been conquered?',
choices: ['The Reach', 'Dorne', 'Essos', 'The North', 'Westeros'],
correctAnswer: 3
},
{
question: "Who confides to Littlefinger that she doesn't want to be a queen, she wants to be THE queen?",
choices: ['Sansa Stark', 'Cersi Lannister', 'Margaery Tyrell', 'Catelyn Stark', ],
correctAnswer: 3
},
{
question: "Which of the following members of the Small Council was secretly giving information to Queen Cersei?",
choices: ['Grand Maester Pycelle', 'Varys', 'Jamie Lannister', 'Maester Aemon', ],
correctAnswer: 1
},
{
question: "How many Targaryens were alive at the start of Game of Thrones?",
choices: ['1', '2', '3', '4', ],
correctAnswer: 3
},
{
question: "What was the name of Catelyn Stark's father?",
choices: ['Lord Hoster', 'Lord Tywin', 'Lord Arryn', 'Lord Craster', ],
correctAnswer: 1
},
{
question: "What was the name of Arya's direwolf?",
choices: ['Ghost', 'Lady', 'Summer', 'Nymeria', ],
correctAnswer: 4
},
{
question: 'Who said, "A very small man can cast a very large shadow"?',
choices: ['Tyrion Lannister', 'Lord Varys', 'Petyr Baelish', 'Jamie Lannister', ],
correctAnswer: 2
},
{
question: 'Who said “When you play a game of thrones you win or you die.”?',
choices: ['Tyrion Lannister', 'Ned Stark', 'Petyr Baelish', 'Cersi Lannister', ],
correctAnswer: 4
},
{
question: 'Who said “When you play a game of thrones you win or you die.”?',
choices: ['Whoops!', 'Something', 'Went', 'Wrong!', ],
correctAnswer: 4
},
];
var userScore = 0;
var count = 0;
var amountOfQuestions = ironThrone.length;
var playerAnswers = [];
var userAnswer;
var myjson;
var arr;
var url = "https://api.myjson.com/bins/2f9pl";
var loggedIn;
var userNameLocal = undefined;
var difference = 1;
function getCookie(){
reg = /name=/i;
if(document.cookie.match(reg)){
var userNameLocalPlaceHolder = document.cookie.replace(reg, " ");
userNameLocal = userNameLocalPlaceHolder.split(";")[0];
$("#yourName").show().text("Welcome Back, " + userNameLocal + "!");
loggedIn = true;
}
}
//loads JSON file
$.getJSON( url, function( json ) {
myjson = json;
arr = $.map(myjson, function(x) { return x });
});
//removes unnecessary values from JSON question string
function questionEditor(){
this.almost = JSON.stringify(arr[count]);
reg = /question|:|{|}|"/ig;
this.almost2 = this.almost.replace(reg,"");
}
function userChoiceDisplayed() {
if (typeof playerAnswers[count] != "undefined") {
$(".img-responsive").css('box-shadow','none');
switch (playerAnswers[count]) {
case '1':
$("#one").css('box-shadow', '3px 3px 7px 8px #5ab2d8');
break;
case '2':
$("#two").css('box-shadow', '3px 3px 7px 8px #5ab2d8');
break;
case '3':
$("#three").css('box-shadow', '3px 3px 7px 8px #5ab2d8');
break;
case '4':
$("#four").css('box-shadow', '3px 3px 7px 8px #5ab2d8');
break;
}
$("#warning").text("Submitted!");
$("#warning").show();
}
}
function logger (){
$('#begin').hide();
getCookie();
if (typeof userNameLocal == 'undefined') {
loggedIn = false;
$('#yourName').show();
$("#login").show();
}
else if (typeof userNameLocal != 'undefined') {
loggedIn = true;
if(userNameLocal != 'undefined' && count == 0 ){
$("#login").hide();
questionChange();
$("#lower").show();
$("#next").show();
$("#back").show();
$("#notMe").show();
//alert(loggedIn);
}
}
}
function getValue() {
playerAnswers[count] = $(this).val();
}
function loginScreen() {
$('#begin').hide();
$("#yourName").show();
$("#lower").show();
$("#login").show();
if(userNameLocal){
logger();
}
}
//changes questions
function questionChange() {
if (count >= 0) {
questionEditor();
$('#question').text(this.almost2);
$("#warning").hide();
$("#first").text(ironThrone[count].choices[0]);
$("#second").text(ironThrone[count].choices[1]);
$("#third").text(ironThrone[count].choices[2]);
$("#fourth").text(ironThrone[count].choices[3]);
if(count > 0){
$("#notMe").hide();
}
}
}
//shows user their score at end of game
function scoreScreen() {
if (count + difference >= ironThrone.length) {
$("#question").hide();
$("h1").css("font-size", "100px");
$("body").css('background-image','url(https://wallpaperscraft.com/image/game_of_thrones_series_throne_power_sword_2017_1920x1080.jpg)');
for (i = 0; i < ironThrone.length; i++) {
if (ironThrone[i].correctAnswer == playerAnswers[i]) {
userScore += 1;
}
return;
}
$("label").hide();
$("input:radio").hide();
$("#lower").hide();
$(".radio").hide();
$("#warning").hide();
$("h1").text("Your Score:");
$("#scoreNumber").text(userScore);
$("#scoreNumber").hide();
$("#scoreNumber").fadeIn(2000);
$("#retry").show();
return;
}
}
$(".img-responsive").on('click', function() {
$(".img-responsive").css('box-shadow','none');
$(this).css('box-shadow', '3px 3px 7px 8px #5ab2d8')
playerAnswers[count] = $(this).val();
count++;
questionChange();
$("#question").add("#choices").animate({left: "-=100%"},"slow");
$("#question").add("#choices").delay(1000).animate({left: "+=100%"},"slow");
$("#question").add("#choices").delay(1000).css('right','100%');
});
$('#begin').on('click', function() {
$("#submit").show();
logger();
questionChange();
});
//Allows user to move to next question after current is answered
$('#next').on('click', function() {
$(".img-responsive").css('box-shadow','none');
count++
questionChange();
userChoiceDisplayed();
});
//allows user to move backwwards once first question is answered
$("#back").on('click', function() {
if (count > 0) {
$('#warning').show();
count--
questionChange();
userChoiceDisplayed();
}
});
//adds user's answer to array
$('#submit').on('click', function() {
// $("#submit").hide();
$("#choices").show();
$("#question").show();
$("#lower").show();
if (typeof playerAnswers[count] == 'undefined' && loggedIn == false) {
userNameLocal = $("#enterName").val();
document.cookie ="name="+userNameLocal.toString();
$("#login").hide();
$("#yourName").text(userNameLocal);
$("#yourName").add("#notMe").show()
logger();
$("#question").show();
}
$(".radio").show();
$("#yourName").show().text("Logged in as " + userNameLocal);
});
//presents button that restarts quiz
$("#retry").on('click',function(){
count = 0;
userScore = 0;
playerAnswers = [];
$("h1").removeAttr('style');
$("#scoreNumber").hide();
$("label").show();
$("#lower").show();
$("input:radio").show();
questionChange();
$("#retry").hide();
});
$("#notMe").on('click', function(){
document.cookie = "name=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
userNameLocal = undefined;
loggedIn = false;
logger();
$("#notMe").add(".radio").add("#yourName").hide();
$("#submit").show();
});
});