-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.html
136 lines (119 loc) · 3.97 KB
/
quiz.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Space Quiz</title>
<style>
body {
font-family: Arial, sans-serif;
}
.question {
font-size: 18px;
margin-bottom: 10px;
}
.options label {
display: block;
margin-bottom: 10px;
cursor: pointer;
}
.result {
font-size: 18px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="question">
<p>1. Which planet is known as the "Red Planet"?</p>
</div>
<div class="options">
<label>
<input type="radio" name="q1" value="wrong"> Venus
</label>
<label>
<input type="radio" name="q1" value="wrong"> Earth
</label>
<label>
<input type="radio" name="q1" value="right"> Mars
</label>
</div>
<div class="question">
<p>2. What is the largest planet in our solar system?</p>
</div>
<div class="options">
<label>
<input type="radio" name="q2" value="right"> Jupiter
</label>
<label>
<input type="radio" name="q2" value="wrong"> Saturn
</label>
<label>
<input type="radio" name="q2" value="wrong"> Uranus
</label>
</div>
<div class="question">
<p>3. Who was the first human to walk on the moon in 1969?</p>
</div>
<div class="options">
<label>
<input type="radio" name="q3" value="wrong"> Alan Shepard
</label>
<label>
<input type="radio" name="q3" value="wrong"> John Glenn
</label>
<label>
<input type="radio" name="q3" value="right"> Neil Armstrong
</label>
</div>
<div class="question">
<p>4. Which space telescope is famous for its stunning images of distant galaxies and nebulae?</p>
</div>
<div class="options">
<label>
<input type="radio" name="q4" value="wrong"> Hubble Space Telescope
</label>
<label>
<input type="radio" name="q4" value="wrong"> Kepler Space Telescope
</label>
<label>
<input type="radio" name="q4" value="right"> Hubble Space Telescope
</label>
</div>
<div class="question">
<p>5. What causes a solar eclipse?</p>
</div>
<div class="options">
<label>
<input type="radio" name="q5" value="wrong"> The moon casting a shadow on the Earth
</label>
<label>
<input type="radio" name="q5" value="wrong"> Earth casting a shadow on the moon
</label>
<label>
<input type="radio" name="q5" value="right"> The moon passing between the Earth and the Sun
</label>
</div>
<button onclick="checkAnswers()">Submit</button>
<div class="result" id="quiz-result"></div>
<script>
function checkAnswers() {
const answers = {
q1: document.querySelector('input[name="q1"]:checked').value,
q2: document.querySelector('input[name="q2"]:checked').value,
q3: document.querySelector('input[name="q3"]:checked').value,
q4: document.querySelector('input[name="q4"]:checked').value,
q5: document.querySelector('input[name="q5"]:checked').value
};
let score = 0;
for (const answer of Object.values(answers)) {
if (answer === 'right') {
score++;
}
}
const resultElement = document.getElementById("quiz-result");
resultElement.innerHTML = `You got ${score} out of 5 questions right!`;
}
</script>
</body>
</html>