-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (38 loc) · 1.3 KB
/
script.js
File metadata and controls
43 lines (38 loc) · 1.3 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
// Quiz data
const quizData = [
{ question: "Milk mixed with water", correct: "adulterated" },
{ question: "Organic fresh fruits", correct: "safe" },
{ question: "Turmeric with lead salts", correct: "adulterated" },
{ question: "Sugar without any additives", correct: "safe" },
{ question: "Tea leaves with coal tar dyes", correct: "adulterated" }
];
let currentQuestion = 0;
function loadQuestion() {
const q = quizData[currentQuestion];
document.getElementById("question").innerText = q.question;
document.getElementById("feedback").innerText = "";
}
function checkAnswer(answer) {
const q = quizData[currentQuestion];
let feedback = document.getElementById("feedback");
if (answer === q.correct) {
feedback.innerText = "✅ Correct!";
feedback.style.color = "green";
} else {
feedback.innerText = "❌ Wrong! It is " + q.correct.toUpperCase();
feedback.style.color = "red";
}
// Load next question after 2 sec
setTimeout(() => {
currentQuestion++;
if (currentQuestion < quizData.length) {
loadQuestion();
} else {
document.getElementById("quiz-container").innerHTML = "<h2>🎉 Quiz Finished! Great Job!</h2>";
}
}, 2000);
}
// Start quiz
if (document.getElementById("question")) {
loadQuestion();
}