-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
300 lines (275 loc) · 12.8 KB
/
main.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
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
document.getElementById("skipbtn").style.display = "none";
document.getElementById("submitbtn").style.display = "none";
document.getElementById("page2_view").style.display = "none";
var questions1 = [
"1) I have ears, mouth and nose but I am not a human. Who am I?",
"2) Can you find the smallest positive number that is divisible by 15 that consists ONLY of ones and zeroes (e.g. 10, 11, 100, etc.)? Note that you don’t need a calculator to solve the problem.",
"3) I have a 9 letter word, 123456789. All 9 letters can be versatile, 345 is very very relevant, if you're 6789, you must be intelligent. What is the word?",
"4) Where does Fourth always come before Third?",
"5) Complete the series. 2 8 23 58 135 ???",
];
var questions2 = [
"1) What can answer in any language? What can speak without a mouth? What can hear without an ear?",
"2) What letter is next in the series? T F S E T T ??",
"3) If you feed me, I live. If you give me a drink, I die. What am I? ",
"4) I have a 10 letter word, 0123456789. All 10 letters - make something easier to notice. If you have 2345, you can buy things, if you 789 those things, hunger is in the past. Planes and trains are expected to follow their 987. What is the word?",
"5) I Can be used to charge a phone but I do not covert AC to DC. What am I? (*This is a TWO word answer)",
];
var questions3 = [
"1) Mr.Singh was killed on Sunday afternoon. The wife said she was reading a book. The butler said he was taking a shower. The chef said he was making breakfast. The maid said she was folding clothes, and the gardener said he was planting tomatoes. Who did it?",
"2) I can't go left, I can't go right. But I do move. I'm forever stuck in one axis. What am I?",
"3) Complete the series: 1 1 2 3 7 16 31 95 ???",
"4) Where does Fourth always come before Third?",
"5) Rose, Hema, and Robin race each other in a 100 meters race. All of them run at a constant speed throughout the race. Rose beats Hema by 20 meters. Hema beats Robin by 20 meters. How many meters does Rose beat Robin by?",
];
var questions4 = [
"1) There are 7 girls in a bus. Each girl has 7 backpacks. In each backpack, there are 7 cats. For every cat, there are 7 kittens. How many legs are there in the bus? (Assume there is no bus driver)",
"2) I Can be used to charge a phone but I do not covert AC to DC. What am I? (*This is a TWO word answer)",
"3) Complete the series. 51 55 71 107 171 ??",
"4) I have a 9 letter word, 123456789. All 9 letters can be versatile, 345 is very very relevant, if you're 6789, you must be intelligent. What is the word?",
"5) I've face but I'm not a human. I've hands but i don't have finger. I blow air but I don't have mouth.",
];
var questions5 = [
"1) Can you find the smallest positive number that is divisible by 15 that consists ONLY of ones and zeroes (e.g. 10, 11, 100, etc.)? Note that you don’t need a calculator to solve the problem.",
"2) I can't go left, I can't go right. But I do move. I'm forever stuck in one axis. What am I?",
"3) I have a 10 letter word, 0123456789. All 10 letters - make something easier to notice If you have 2345, you can buy things, If you 789 those things, hunger is in the past. Planes and trains are expected to follow their 987. What is the word?",
"4) Complete the series: 31 30 34 7 71 ??",
"5) Where does Fourth always come before Third?",
];
//Checking if input string is empty or not for mode 0.
document.getElementById("loginbtn").onclick = function () {
var Name = document.getElementById("userName").value.trim();
var Password = document.getElementById("password").value.toLowerCase().trim();
if (Name == "" || Password == "") {
document.getElementById("loginInstruction").innerHTML =
"Please fill in the details.";
} else {
mode = 0;
serialJSON["name"] = Name;
serialJSON["password"] = Password;
if (document.getElementById("page2_view").style.display == "block") {
var Answer = document.getElementById("Ans").value.toLowerCase().trim();
if (Answer == "") {
alert("Fill in the answer!");
return false;
} else {
serialJSON["Answer"] = Answer;
mode = 1;
}
}
successful(mode, serialJSON);
}
return false;
};
//checking input of answers for mode 1.
document.getElementById("submitbtn").onclick = function () {
var Name = document.getElementById("userName").value.trim();
var Password = document.getElementById("password").value.toLowerCase().trim();
var Answer = document.getElementById("Ans").value.toLowerCase().trim();
if (Name == "" || Password == "" || Answer == "") {
alert("Please fill in all the details!");
} else {
document.getElementById("attemptsInstruction").innerHTML = "";
mode = 1;
serialJSON["name"] = Name;
serialJSON["password"] = Password;
serialJSON["Answer"] = Answer;
successful(mode, serialJSON);
}
return false;
};
//for mode 3.
document.getElementById("skipbtn").onclick = function () {
var Name = document.getElementById("userName").value.trim();
var Password = document.getElementById("password").value.toLowerCase().trim();
if (Name == "" || Password == "") {
document.getElementById("loginInstruction").innerHTML =
"Please fill in the details.";
} else {
mode = 2;
serialJSON["name"] = Name;
serialJSON["password"] = Password;
successful(mode, serialJSON);
}
return false;
};
//post request.
var serialJSON = {};
var mode;
function successful(mode) {
serialJSON["mode"] = mode;
document.getElementById("loading").style.display = "block";
$.ajax({
url: "https://script.google.com/macros/s/AKfycbxaAS7i8roOove79HVNrCiPn_4ZQ-4JCrAXsptqH35l4W_7HRwE/exec",
type: "POST",
data: serialJSON,
success: function (res) {
//Wrong username and password.
if (res.ReturnedStatus == 0) {
document.getElementById("loginInstruction").innerHTML =
"wrong credentials";
}
//correct username and password.
else if (res.ReturnedStatus == 1) {
document.getElementById("loginInstruction").innerHTML = "";
if (mode == 0) {
//if already played and won
if (res.WinStatus == 1) {
window.location.replace("Final-pg.html");
//WON PAGE............
}
//if already played and lost.
else if (res.Attempts >= 5) {
window.location.replace("Final-pg2.html");
//FAIL PAGE.....
}
//to start/continue playing.
else {
//Checking the group number.
if (res.grpNo == 1) {
document.getElementById("Que").innerHTML =
questions1[res.current_question];
} else if (res.grpNo == 2) {
document.getElementById("Que").innerHTML =
questions2[res.current_question];
} else if (res.grpNo == 3) {
document.getElementById("Que").innerHTML =
questions3[res.current_question];
} else if (res.grpNo == 4) {
document.getElementById("Que").innerHTML =
questions4[res.current_question];
} else if (res.grpNo == 5) {
document.getElementById("Que").innerHTML =
questions5[res.current_question];
}
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
document.getElementById("loginbtn").style.display = "none";
document.getElementById("skipbtn").style.display = "inline";
document.getElementById("submitbtn").style.display = "inline";
document.getElementById("page2_view").style.display = "block";
document.getElementById(
"hangman_pic"
).src = `man_${res.Attempts}.png`;
if (res.SkipStatus == 1) {
document.getElementById("skipbtn").style.display = "none";
document.getElementById("Ans").value = "";
} else if (res.Attempts == 4) {
document.getElementById("skipbtn").style.display = "none";
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
document.getElementById("Ans").value = "";
}
}
} else if (mode == 1) {
if (res.Attempts == 4) {
document.getElementById("skipbtn").style.display = "none";
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
document.getElementById("Ans").value = "";
}
//correct answer
if (res.Ans_Status == 1) {
if (res.WinStatus == 1 || res.current_question == 5) {
window.location.replace("Final-pg.html");
//alert('You have clered the round!');
//WON PAGE....
} else {
alert("Congrats! Correct Answer.");
//Checking the group number.
if (res.grpNo == 1) {
document.getElementById("Que").innerHTML =
questions1[res.current_question];
} else if (res.grpNo == 2) {
document.getElementById("Que").innerHTML =
questions2[res.current_question];
} else if (res.grpNo == 3) {
document.getElementById("Que").innerHTML =
questions3[res.current_question];
} else if (res.grpNo == 4) {
document.getElementById("Que").innerHTML =
questions4[res.current_question];
} else if (res.grpNo == 5) {
document.getElementById("Que").innerHTML =
questions5[res.current_question];
}
document.getElementById("Ans").value = "";
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
}
}
//else if ..wrong answer
else if (res.Ans_Status == 0) {
if (res.Attempts >= 5) {
window.location.replace("Final-pg2.html");
//FAIL PAGE.....
}
//pic update.
else {
alert("Wrong answer! Lost an attempt.");
document.getElementById(
"hangman_pic"
).src = `man_${res.Attempts}.png`;
document.getElementById("Ans").value = "";
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
}
}
} else if (mode == 2) {
if (res.Attempts == 4) {
document.getElementById("skipbtn").style.display = "none";
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
} else if (res.WinStatus == 1) {
window.location.replace("Final-pg.html");
//WON PAGE.......
} else if (res.SkipStatus == 1 || res.Attempts == 5) {
alert("Answer skipped! Lost an attempt.");
document.getElementById(
"hangman_pic"
).src = `man_${res.Attempts}.png`;
document.getElementById(
"attemptsInstruction"
).innerHTML = `${res.Attempts} attempts used out of 5.`;
document.getElementById("skipbtn").style.display = "none";
if (res.Attempts == 5) {
window.location.replace("Final-pg2.html");
//FAIL PAGE......
} else {
//Checking the group number.
if (res.grpNo == 1) {
document.getElementById("Que").innerHTML =
questions1[res.current_question];
} else if (res.grpNo == 2) {
document.getElementById("Que").innerHTML =
questions2[res.current_question];
} else if (res.grpNo == 3) {
document.getElementById("Que").innerHTML =
questions3[res.current_question];
} else if (res.grpNo == 4) {
document.getElementById("Que").innerHTML =
questions4[res.current_question];
} else if (res.grpNo == 5) {
document.getElementById("Que").innerHTML =
questions5[res.current_question];
}
}
} else if (res.SkipStatus >= 1) {
document.getElementById("skipbtn").style.display = "none";
}
}
}
document.getElementById("loading").style.display = "none";
},
error: function (res) {
alert("There has been a error! please refresh the page and try again.");
document.getElementById("loading").style.display = "none";
},
});
}