-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path13.html
More file actions
86 lines (78 loc) · 3.19 KB
/
Copy path13.html
File metadata and controls
86 lines (78 loc) · 3.19 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Quiz</title>
</head>
<body>
<h1>Interactive Quiz</h1>
<div id="quizContainer">
<div id="question"></div>
<input type="radio" name="answer" id="option1"> <label for="option1" id="label1"></label><br>
<input type="radio" name="answer" id="option2"> <label for="option2" id="label2"></label><br>
<input type="radio" name="answer" id="option3"> <label for="option3" id="label3"></label><br>
<button id="submit">Submit</button>
</div>
<div id="result"></div>
<script>
const questions = [
{
question: "Does BIT have a GDSC club ?",
options: ["Nope", "Yes", "Not sure"],
correctAnswer: "Yes"
},
{
question: "What is the parent company of Google",
options: ["Meta", "Amazon", "Alphabet"],
correctAnswer: "Alphabet"
},
{
question: "What is the full form of GDSC",
options: ["Gladly Dancing Students Club", "Google Developers Student Club", "Gastronomical Dynamic Strangers Club"],
correctAnswer: "Google Developers Student Club"
}
];
const quizContainer = document.getElementById("quizContainer");
const questionElement = document.getElementById("question");
const option1 = document.getElementById("option1");
const option2 = document.getElementById("option2");
const option3 = document.getElementById("option3");
const label1 = document.getElementById("label1");
const label2 = document.getElementById("label2");
const label3 = document.getElementById("label3");
const submitButton = document.getElementById("submit");
const resultElement = document.getElementById("result");
let currentQuestion = 0;
let score = 0;
function loadQuestion() {
const current = questions[currentQuestion];
questionElement.textContent = current.question;
label1.textContent = current.options[0];
label2.textContent = current.options[1];
label3.textContent = current.options[2];
}
function checkAnswer() {
const selectedOption = document.querySelector("input[name='answer']:checked");
if (selectedOption) {
const answer = selectedOption.labels[0].textContent;
if (answer === questions[currentQuestion].correctAnswer) {
score++;
}
currentQuestion++;
if (currentQuestion < questions.length) {
loadQuestion();
} else {
showResult();
}
}
}
function showResult() {
quizContainer.style.display = "none";
resultElement.textContent = `You scored ${score} out of ${questions.length}.`;
}
submitButton.addEventListener("click", checkAnswer);
loadQuestion();
</script>
</body>
</html>