-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
28 lines (25 loc) · 1009 Bytes
/
script.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
document.getElementById("submit-btn").addEventListener("click", function() {
const correctAnswers = ["Argentina", "Meta", "Greece", "Tech for Good", "India", "Netflix", "Paris", "Avatar 3", "UK", "Fusion Energy"];
let score = 0;
let wrongQuestions = [];
for (let i = 1; i <= 10; i++) {
const options = document.getElementsByName(`answer${i}`);
let selectedAnswer = "";
for (const option of options) {
if (option.checked) {
selectedAnswer = option.nextElementSibling.textContent;
break;
}
}
if (selectedAnswer === correctAnswers[i - 1]) {
score++;
} else {
wrongQuestions.push(i);
}
}
let resultText = `You scored ${score} out of 10.`;
if (wrongQuestions.length > 0) {
resultText += ` You got the following questions wrong: ${wrongQuestions.join(", ")}.`;
}
document.getElementById("result-text").textContent = resultText;
});