-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
281 lines (229 loc) · 11.9 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Quiz-Countries and Capitals</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Anton&family=Pacifico&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Balsamiq+Sans&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Bangers&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital@1&display=swap" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- <script language="JavaScript" type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/jquery-ui-personalized-1.5.2.packed.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/sprinkle.js"></script> -->
</head>
<body>
<header>
<!-- maybe add nav bar once done-->
</header>
<section class="home-container" id="home-container">
<h1 class ="pageTitle">The Capital-City quiz</h1>
<div class="home-sub">
<p>How good are you in Geography? <br>Find out by playing this fun and educational game.</p>
<p>INSTRUCTIONS:</p>
<ol>
<li>Press the button Start to see the first question. </li>
<li>Select your answer, only one option is allowed.</li>
<li>You can click submit to check if you clicked the right answer. Then, click next to view the following question.</li>
<li>If you prefer you can submit all you answers first, and then, click "Check All Answers".</li>
</ol>
<p>Good Luck!</p>
<button type="submit" id="btnsubmit">Check All Answers</button>
<button id="start">Start</button>
<button id="restart"><a href="./index.html">Restart Game</a></button>
<br>
<br>
</div>
</section>
<div id="quizDiv" ></div>
<div id="resultsDiv">
<div class="link">
<a href="#home-container">Go top and check results</a>
</div>
</div>
<!-- <script type="module" src="js/final-index.js"></script> -->
<script >
const questions = [
{
qstn: ' What is the capital of Spain ?',
options: ['Barcelona', 'San Marino', 'Madrid', 'Buenos Aires'],
correct: 'Madrid',
bgImage: "images/Madrid.jpg",
country: 'Spain'
},
{
qstn: ' What is the capital of Greece ?',
options: ['Thessaloniki', 'Santorini', 'Mykonos', 'Athens'],
correct: 'Athens',
bgImage: "images/Athens.jpg",
country: 'Greece'
},
{
qstn: ' What is the capital of Turkey ?',
options: ['Ankara', 'Istanbul', 'Constantinople', 'Leon'],
correct: 'Ankara',
bgImage: 'images/Ankara.jpg',
country: 'Turkey'
},
{
qstn: ' What is the capital of Senegal ?',
options: ['Dakar', 'Banjul', 'Abuja', 'antananarivo'],
correct: 'Dakar',
bgImage: 'images/Senegal.jpg',
country: 'Senegal'
},
{
qstn: ' What is the capital of Ghana ?',
options: ['Luanda', 'Accra', 'Yaounde', 'Poto-Novo'],
correct: 'Accra',
bgImage: 'images/Ghana.jpg',
country: 'Ghana'
}
];
function buildQuiz(questions){
const quizDiv = document.getElementById('quizDiv');
const btnsubmit = document.getElementById('btnsubmit');
questions.map((question) => {
const questionDiv = document.createElement('div');
questionDiv.className = 'questionDiv';
questionDiv.id = 'questionDiv' + question.correct;
//styling
questionDiv.style.cssText = " padding: 30px; display: flex; flex-direction: column; justify-content: center; align-items: center; border: 0px";
questionDiv.style.minWidth = '100%';
questionDiv.style.height = '600px';
questionDiv.style.overflow = 'hidden';
questionDiv.style.backgroundImage = "linear-gradient(black, black), " + "url('" + question.bgImage + "')";
questionDiv.style.backgroundBlendMode = 'saturation';
questionDiv.style.backgroundRepeat = "no-repeat";
questionDiv.style.backgroundSize = 'cover';
questionDiv.style.backgroundPosition = 'center';
const qstnTitle = document.createElement('h2');
qstnTitle.textContent = question.qstn;
qstnTitle.className = 'qstn';
qstnTitle.style.cssText = " font-family: 'Pacifico', cursive; \
color: white; background-color: rgba(0, 0, 0, 0.5) "
const optionsForm = document.createElement('form');
optionsForm.className = 'optionsForm';
const submitNextDiv = document.createElement('div');
submitNextDiv.className = 'submitNextDiv';
submitNextDiv.style.cssText = 'border-color: green; border-style: thin; background-color: white';
const submitDiv = document.createElement('div');
submitDiv.addEventListener('click', respondClick2)
submitDiv.className = 'submitDiv';
submitDiv.textContent = 'Submit';
submitDiv.style.cssText = 'border-setyle: thin; background-color: grey';
function respondClick2(){
question.options.map((option) => {
if(document.getElementById(option).checked && (option == question. correct)) {
const feedback = document.createElement('p');
feedback.textContent = 'You are right! ' + option + ' is the capital of ' + question.country;
feedback.style.cssText = "font-family: 'Roboto', sans-serif; background-color: white; padding: 10px";
questionDiv.appendChild(feedback);
let optionDiv = document.getElementById('optionDiv' + option);
optionDiv.style.color = 'green';
questionDiv.style.backgroundImage = " " + "url('" + question.bgImage + "')";
questionDiv.style.backgroundBlendMode = 'none';
}
if(document.getElementById(option).checked && (option !== question. correct)) {
const feedback = document.createElement('p');
feedback.textContent = 'Try again! ' + option + ' is not the correct answer...';
feedback.style.cssText = "font-family: 'Roboto', sans-serif; background-color: white; padding: 10px";
questionDiv.appendChild(feedback);
let optionDiv = document.getElementById('optionDiv' + option);
optionDiv.style.color = 'red';
optionsForm.style.backgroundColor = 'red';
questionDiv.style.backgroundImage = "linear-gradient(black, red), " + "url('" + question.bgImage + "')";
questionDiv.style.backgroundBlendMode = 'multiply';
}
})
}
const nextDiv = document.createElement('div');
nextDiv.className = 'nextDiv';
nextDiv.id = 'nextDiv';
nextDiv.textContent = 'Next';
nextDiv.style.cssText = 'border-setyle: thin; background-color: black';
question.options.map((option) =>{
const optionDiv = document.createElement('div');
optionDiv.id = 'optionDiv' + option;
const inputForm = document.createElement('input');
inputForm.type = 'radio';
inputForm.name = question.correct;
inputForm.id = option;
const inputLabel = document.createElement('label');
inputLabel.for = option;
inputLabel.textContent = option;
inputLabel.style.cssText = "font-family: 'Balsamiq Sans', cursive;"
optionDiv.appendChild(inputForm);
optionDiv.appendChild(inputLabel);
optionDiv.style.backgroundColor= 'rgba(0, 0, 0, 0.5)';
optionDiv.style.padding = '10px';
optionsForm.appendChild(optionDiv);
optionsForm.style.cssText = " display: grid; \
grid-template-columns: repeat(auto-fit, 186px); \
grid-gap: 5px; color: white; font-family: 'Anton', sans-serif; \
justify-content: center; margin: 20px; padding: 5px " ;
});
submitNextDiv.appendChild(submitDiv);
submitNextDiv.appendChild(nextDiv);
questionDiv.appendChild(qstnTitle);
questionDiv.appendChild(optionsForm);
questionDiv.appendChild(submitNextDiv);
quizDiv.appendChild(questionDiv);
$(".nextDiv").click(function() {
var next;
next = $(this).parent().parent().next();
$('html,body').animate({scrollTop: next.offset().top});
})
});
$("#start").click(function() {
var elmnt = document.getElementById("quizDiv");
console.log(elmnt);
console.log('hi');
elmnt.scrollIntoView();
})
btnsubmit.addEventListener('click', respondClick);
var questionArray = questions;
function respondClick(){
//testing
//console.log(questionArray);
let countCorrect = 0;
//testing
// console.log(document.getElementById('Sitges').checked);
questionArray.map((question) =>{
const quizDiv2 = document.getElementById('questionDiv' + question.correct);
const resultQuestion = document.createElement('p');
question.options.map((option) =>{
if (document.getElementById(option).checked && (option == question.correct)) {
// console.log('testing correct');
countCorrect = countCorrect + 1;
console.log('You have' + countCorrect + 'answers correct');
resultQuestion.textContent = 'You are right! ' + option + ' is the capital of ' + question.country;
resultQuestion.style.cssText = "font-family: 'Roboto', sans-serif; background-color: white; padding: 10px";
let optionDiv = document.getElementById('optionDiv' + option);
optionDiv.style.color = "green";
quizDiv2.style.backgroundImage = " " + "url('" + question.bgImage + "')";
quizDiv2.style.backgroundBlendMode = 'none';
console.log(quizDiv2);
}
if (document.getElementById(option).checked && option != question.correct) {
// console.log('testing incorrect');
resultQuestion.textContent = 'Try again! ' + option + ' is not the correct answer...';
resultQuestion.style.cssText = " font-family: 'Roboto', sans-serif; background-color: white; padding: 10px";
let optionDiv = document.getElementById('optionDiv' + option);
optionDiv.style.color = 'red';
// optionsForm.style.backgroundColor = 'red';
quizDiv2.style.backgroundImage = "linear-gradient(black, red), " + "url('" + question.bgImage + "')";
quizDiv2.style.backgroundBlendMode = 'multiply';
}
});
quizDiv2.appendChild(resultQuestion);
});
}
};
buildQuiz(questions);
</script>
</body>
</html>