-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
223 lines (190 loc) · 6.4 KB
/
script.js
File metadata and controls
223 lines (190 loc) · 6.4 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
var count = 0;
var wrongAns = 0;
var scoreCount = 0;
var streakCount = 0;
var name;
var lives = 3;
const ans = document.getElementById('answer');
const docQ = document.getElementById('question');
const docScore = document.getElementById('score');
const docStreak = document.getElementById('streak');
const docCountQ = document.getElementById('countQ');
const docFailScore = document.getElementById('failScore');
const docFailName = document.getElementById('failName');
const docWinName = document.getElementById('winName');
const docWinScore = document.getElementById('winScore');
const docExitName = document.getElementById('exitName');
const docExitScore = document.getElementById('exitScore');
function isEmpty(){
var name = window.prompt("Enter your name: ");
this.name = name;
if(name.trim()==null || name.trim()==""){
console.log("Name not set");
}
else{
alert("Your name has been set as " + name);
window.location.href = "category.html";
}
}
function question(question, answer,points){
this.question = question;
this.answer = answer;
this.points = points;
}
var foodQuestions = [new question('What is the local name for Shadow Beni?','BANDANYA',5),
new question('What is the name of the dish that is made by soaking and boiling pieces of salted fish, then blending them with tomatoes, hot peppers, sweet peppers, onions, and oil?','SALTFISH BULJOL',10),
new question('What is a famous dish we buy at Maracas Bay most of the time?','BAKE AND SHARK',15),
new question('What is a famous soup made with fish and vegetables in Trinidad and Tobago?','FISH BROTH',20),
new question('What is the name of the most common street food in Trinidad and Tobago?','DOUBLES',25)];
var personQuestions = [new question('Who was the first President of Trinidad and Tobago?','SIR ELLIS CLARKE',5),
new question('Who was the first female Prime Minister of Trinidad and Tobago?','KAMLA PERSAD-BISSESSAR',10),
new question('Which person led the 1990 coup to overthrow the government?','YASIN ABU BAKR',15),
new question("Name the legendary cricketer, known as the 'Prince of Trinidad'",'BRIAN LARA',20),
new question('Who is the most popular Soca Artiste?','MACHEL MONTANO',25)];
var geographyQuestions = [new question('Name the most well known hill in south Trinidad','SAN FERNANDO HILL',5),
new question('Trinidad is home to the largest round-about in the world. What is its name?','QUEENS PARK SAVANNAH',10),
new question('Name the two identical towers in the capital of Trinidad','TWIN TOWERS',15),
new question('Where is the protected nesting area for the national bird of Trinidad?','BIRD SANCTUARY',20),
new question('Name the largest natural deposit of asphalt on the island','PITCH LAKE',25)];
var celebrations = [new question('What is the largest street parade, usually in February called?','CARNIVAL',5),
new question('Name the music festival that usually happens every April in Tobago','TOBAGO JAZZ FESTIVAL',10),
new question('What day marks the commemoration of liberation from chattel slavery?','EMANCIPATION DAY',15),
new question('Name the week-long mid-year event celebrating the rich diversity of cultures','WE BEAT FESTIVAL',20),
new question('A historic marking of the cross-cultural relationship between the Amerindians and the Roman Catholic Church. The festival is held in August in honour of the remaining Caribs on the islands. What is it called?','SANTA ROSA FESTIVAL',25)];
function loadQuestions(x,y){
switch(y){
case 1:{
docCountQ.innerText = 'Question ' + (x+1);
docQ.innerText = foodQuestions[x].question;
break;
}
case 2:{
docCountQ.innerText = 'Question ' + (x+1);
docQ.innerText = personQuestions[x].question;
break;
}
case 3:{
docCountQ.innerText = 'Question ' + (x+1);
docQ.innerText = geographyQuestions[x].question;
break
}
case 4:{
docCountQ.innerText = 'Question ' + (x+1);
docQ.innerText = celebrations[x].question;
break
}
default:console.log('ERROR!');
}
}
function submit(y){
if(emptyAnswer()){
if(checkAnswer(y)){
if(count==4){
window.location.href = "youWin.html?"+name+"?"+scoreCount;
}
else{
count++;
loadQuestions(count,y);
ans.value = "";
}
}
else{
if(count==4){
window.location.href = "fail.html?"+name+"?"+scoreCount;
}
else{
count++;
loadQuestions(count,y);
ans.value = "";
}
}
}
}
function emptyAnswer(){
if (ans.value == null || ans.value.trim() == "" ) {
alert('Please enter an answer');
return false;
}
else{
return true;
}
}
function checkAnswer(y){
var check;
switch(y){
case 1:{
check = foodQuestions[count].answer;
break;
}
case 2:{
check = personQuestions[count].answer;
break;
}
case 3:{
check = geographyQuestions[count].answer;
break
}
case 4:{
check = celebrations[count].answer;
break
}
default:console.log('ERROR!');
}
if(ans.value.toUpperCase().trim()==check){
alert('Correct Answer');
lives = 3;
wrongAns = 0;
updateScore();
streak();
return true;
}
else{
streakCount = 0;
docStreak.innerText = streakCount;
docScore.innerText = scoreCount;
lives--;
alert('Wrong Answer\nYou entered: '+ans.value+'\nCorrect Answer: '+check+"\nLives Remaining: " + lives);
wrongAns++;
if(wrongAns>2){
window.location.href = "fail.html?"+name+"?"+scoreCount;
}
return false;
}
}
function updateScore() {
scoreCount += foodQuestions[count].points;
docScore.innerText = scoreCount;
}
function streak(){
streakCount++;
docStreak.innerText = streakCount;
}
function fail(){
var queryString = location.search.substring(1);
var a = queryString.split("?");
docFailName.innerText = "Better Luck next time " + a[0];
docFailScore.innerText = "Your score is " + a[1];
}
function win(){
var queryString = location.search.substring(1);
var a = queryString.split("?");
if(parseInt(a[1]) == 75){
docWinName.innerText = "CONGRATS " + a[0];
docWinScore.innerText = "Your score is " + a[1];
}
else if(parseInt(a[1]) < 75){
var queryString = location.search.substring(1);
var a = queryString.split("?");
docWinName.innerText = a[0] + " has received a commendation reward.";
docWinScore.innerText = "Your score is " + a[1];
}
}
function exit(){
window.location.href = "exit.html?"+name+"?"+scoreCount;
}
function thanks(){
var queryString = location.search.substring(1);
var a = queryString.split("?");
docExitName.innerText = "Come again " + a[0];
docExitScore.innerText = "Your score is " + a[1];
}