-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 1.39 KB
/
index.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
document.addEventListener('DOMContentLoaded', function () {
const optionsList = document.getElementById('options-list');
optionsList.addEventListener('click', function (event) {
if (event.target.tagName === 'LI') {
checkAnswer(event.target);
}
});
});
function checkAnswer(selectedOption) {
// Define the correct answer (change this based on your quiz)
const correctAnswer = "A. Paris";
const resultElement = document.getElementById('result');
// Check if the selected option is correct
if (selectedOption.textContent === correctAnswer) {
selectedOption.classList.add("correct");
resultElement.textContent = "Correct!";
resultElement.style.color = "#7FFF7F"; // Green
} else {
selectedOption.classList.add("incorrect");
// Highlight the correct answer in green
const options = document.querySelectorAll('#options-list li');
options.forEach(option => {
if (option.textContent === correctAnswer) {
option.classList.add("correct");
}
});
resultElement.textContent = "Wrong! The correct answer is " + correctAnswer;
resultElement.style.color = "#FF7F7F"; // Red
}
// Disable further clicks on options
const options = document.querySelectorAll('#options-list li');
options.forEach(option => {
option.style.pointerEvents = 'none';
});
}