forked from shaun099/PACE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquiz.js
280 lines (256 loc) · 8.33 KB
/
quiz.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
const startBtn = document.querySelector(`.start-btn`);
const popupInfo = document.querySelector(`.popup-info`);
const exitBtn = document.querySelector(`.exit-btn`);
const main = document.querySelector(`.main`);
const continueBtn = document.querySelector(`.continue-btn`);
const quizSection = document.querySelector(`.Quiz-section`);
const quizBox = document.querySelector(`.quiz-box`);
const resultBox = document.querySelector(`.result-box`);
const tryAgainBtn = document.querySelector(`.tryAgain-btn`);
const goHomeBtn = document.querySelector(`.goHome-btn`);
const nextBtn = document.querySelector(`.next-btn`);
const optionList = document.querySelector(`.option-list`);
let questions = [
{
numb: 1,
question:
"What is the primary objective of the PACE satellite in ocean monitoring?",
answer: "c. To monitor phytoplankton and ocean color",
options: [
`a. To study tectonic plate movements`,
`b. To measure sea surface temperatures`,
`c. To monitor phytoplankton and ocean color`,
`d. To track marine life migration patterns`,
],
},
{
numb: 2,
question:
"How does the PACE satellite help in studying the Earth's atmosphere?",
answer: "b. By measuring aerosol particles and cloud cover",
options: [
`a. By tracking thunderstorms and hurricanes`,
`b. By measuring aerosol particles and cloud cover`,
`c. By detecting volcanic eruptions`,
`d. By predicting weather patterns`,
],
},
{
numb: 3,
question:
"Why is the measurement of ocean color important for the PACE satellite's mission?",
answer: "d. It provides insights into phytoplankton populations",
options: [
`a. It indicates ocean depth`,
`b. It reveals the presence of pollutants`,
`c. It helps track ocean currents`,
`d. It provides insights into phytoplankton populations`,
],
},
{
numb: 4,
question:
"In what way does the PACE satellite contribute to climate change research?",
answer:
"c. By measuring how aerosols and clouds impact global temperatures",
options: [
`a. By monitoring volcanic ash clouds`,
`b. By analyzing changes in ice caps`,
`c. By measuring how aerosols and clouds impact global temperatures`,
`d. By tracking forest fires`,
],
},
{
numb: 5,
question: "How does PACE improve our understanding of air quality?",
answer: "c. By measuring aerosol particles that affect air quality",
options: [
`a. By detecting carbon emissions from vehicles`,
`b. By monitoring deforestation`,
`c. By measuring aerosol particles that affect air quality`,
`d. By tracking CO2 levels in the upper atmosphere`,
],
},
{
numb: 6,
question:
"Which type of data does PACE primarily collect to monitor ocean ecosystems?",
answer: "a. Optical data",
options: [
`a. Optical data`,
`b. Acoustic data`,
`c. Satellite temperature data`,
`d. Magnetic field data`,
],
},
{
numb: 7,
question:
"What technology does the PACE satellite use to capture ocean color?",
answer: "b. Spectral imaging",
options: [
`a. Infrared sensors`,
`b. Spectral imaging`,
`c. Laser altimetry`,
`d. Radar altimetry`,
],
},
{
numb: 8,
question:
"How does PACE's monitoring of phytoplankton contribute to food security?",
answer: "d. It helps assess marine productivity",
options: [
`a. By tracking fish populations`,
`b. By measuring water temperature`,
`c. By monitoring ocean currents`,
`d. It helps assess marine productivity`,
],
},
{
numb: 9,
question:
"What is the expected lifespan of the PACE satellite once operational?",
answer: "c. 5 years",
options: [`a. 2 years`, `b. 3 years`, `c. 5 years`, `d. 10 years`],
},
{
numb: 10,
question:
"Which other satellite program complements the objectives of the PACE mission?",
answer: "b. NASA's Ocean Color Climate Change Initiative",
options: [
`a. The European Space Agency's Sentinel-3`,
`b. NASA's Ocean Color Climate Change Initiative`,
`c. The Global Precipitation Measurement Mission`,
`d. The Soil Moisture Active Passive Mission`,
],
},
{
numb: 10,
question:
"Which other satellite program complements the objectives of the PACE mission?",
answer: "b. NASA's Ocean Color Climate Change Initiative",
options: [
`a. The European Space Agency's Sentinel-3`,
`b. NASA's Ocean Color Climate Change Initiative`,
`c. The Global Precipitation Measurement Mission`,
`d. The Soil Moisture Active Passive Mission`,
],
},
];
let questionCount = 0;
let questionNumb = 1;
let userScore = 0;
// Function Definitions
startBtn.onclick = () => {
popupInfo.classList.add(`active`);
main.classList.add(`active`);
};
exitBtn.onclick = () => {
popupInfo.classList.remove(`active`);
main.classList.remove(`active`);
};
continueBtn.onclick = () => {
quizSection.classList.add(`active`);
popupInfo.classList.remove(`active`);
main.classList.remove(`active`);
quizBox.classList.add(`active`);
showQuestiions(0);
questionCounter(1);
headerScore();
};
tryAgainBtn.onclick = () => {
quizBox.classList.add(`active`);
resultBox.classList.remove(`active`);
nextBtn.classList.remove(`active`);
questionCount = 0;
questionNumb = 1;
userScore = 0;
showQuestiions(questionCount);
questionCounter(questionNumb);
headerScore();
};
goHomeBtn.onclick = () => {
quizSection.classList.remove(`active`);
resultBox.classList.remove(`active`);
nextBtn.classList.remove(`active`);
questionCount = 0;
questionNumb = 1;
userScore = 0;
};
nextBtn.onclick = () => {
if (questionCount < questions.length - 1) {
questionCount++;
showQuestiions(questionCount);
questionNumb++;
questionCounter(questionNumb);
nextBtn.classList.remove(`active`);
} else {
showResultBox();
}
};
function showQuestiions(index) {
const questionText = document.querySelector(`.question-text`);
questionText.textContent = `${questions[index].numb}. ${questions[index].question}`;
let optionTag = questions[index].options
.map((option) => `<div class="option"><span>${option}</span></div>`)
.join("");
optionList.innerHTML = optionTag;
const option = document.querySelectorAll(`.option`);
for (let i = 0; i < option.length; i++) {
option[i].setAttribute(`onclick`, `optionSelected(this)`);
}
}
function optionSelected(answer) {
let userAnswer = answer.textContent;
let correctAnswer = questions[questionCount].answer;
let allOptions = optionList.children.length;
if (userAnswer === correctAnswer) {
answer.classList.add(`correct`);
userScore++;
headerScore();
} else {
answer.classList.add(`incorrect`);
// Correct option
for (let i = 0; i < allOptions; i++) {
if (optionList.children[i].textContent === correctAnswer) {
optionList.children[i].setAttribute(`class`, `option correct`);
}
}
}
// To choose only one option
for (let i = 0; i < allOptions; i++) {
optionList.children[i].classList.add(`disabled`);
}
nextBtn.classList.add(`active`);
}
function questionCounter(index) {
const questionTotal = document.querySelector(`.question-total`);
questionTotal.textContent = `${index} of ${questions.length} questions`;
}
function headerScore() {
const headerScoreText = document.querySelector(`.header-score`);
headerScoreText.textContent = `Score: ${userScore} / ${questions.length}`;
}
function showResultBox() {
quizBox.classList.remove(`active`);
resultBox.classList.add(`active`);
const scoreText = document.querySelector(`.score-text`);
scoreText.textContent = `Your Score is ${userScore} out of ${questions.length}`;
const circularProgress = document.querySelector(`.circular-progress`);
const progressValue = document.querySelector(`.progress-value`);
let progressStartVal = -1;
let progressEndVal = Math.floor((userScore / questions.length) * 100);
let speed = 20;
let progress = setInterval(() => {
progressStartVal++;
progressValue.textContent = `${progressStartVal}%`;
circularProgress.style.background = `conic-gradient(#245c38 ${
progressStartVal * 3.6
}deg, rgba(255, 255, 255, .1) 0deg)`;
if (progressStartVal === progressEndVal) {
clearInterval(progress);
}
}, speed);
}