-
Notifications
You must be signed in to change notification settings - Fork 5
/
SampleQuiz.html
166 lines (154 loc) · 5.05 KB
/
SampleQuiz.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Fun Trivia Quiz</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
}
.quiz-container {
background-color: #fff;
padding: 30px;
border-radius: 15px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
}
.quiz-container h1 {
text-align: center;
color: #333;
}
.question {
margin-bottom: 25px;
}
.question h2 {
margin-bottom: 10px;
font-size: 1.2em;
color: #555;
}
.options label {
display: block;
margin-bottom: 10px;
cursor: pointer;
}
.options input {
margin-right: 10px;
}
.result {
margin-top: 20px;
padding: 10px;
border-radius: 5px;
font-size: 1.1em;
text-align: center;
transition: all 0.3s ease;
}
.correct {
background-color: #d4edda;
color: #155724;
}
.incorrect {
background-color: #f8d7da;
color: #721c24;
}
button {
display: block;
margin: 20px auto;
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
@media (max-width: 500px) {
.quiz-container {
padding: 20px;
}
.quiz-container h1 {
font-size: 1.5em;
}
button {
width: 100%;
}
}
</style>
</head>
<body>
<div class="quiz-container">
<h1>Fun Trivia Quiz</h1>
<div class="question" id="question1">
<h2>1. What is the capital of France?</h2>
<div class="options">
<label><input type="radio" name="q1" value="Paris"> Paris</label>
<label><input type="radio" name="q1" value="London"> London</label>
<label><input type="radio" name="q1" value="Berlin"> Berlin</label>
<label><input type="radio" name="q1" value="Madrid"> Madrid</label>
</div>
</div>
<div class="question" id="question2">
<h2>2. Which planet is known as the Red Planet?</h2>
<div class="options">
<label><input type="radio" name="q2" value="Mars"> Mars</label>
<label><input type="radio" name="q2" value="Venus"> Venus</label>
<label><input type="radio" name="q2" value="Jupiter"> Jupiter</label>
<label><input type="radio" name="q2" value="Saturn"> Saturn</label>
</div>
</div>
<div class="question" id="question3">
<h2>3. What is the tallest mountain in the world?</h2>
<div class="options">
<label><input type="radio" name="q3" value="Everest"> Mount Everest</label>
<label><input type="radio" name="q3" value="K2"> K2</label>
<label><input type="radio" name="q3" value="Kangchenjunga"> Kangchenjunga</label>
<label><input type="radio" name="q3" value="Makalu"> Makalu</label>
</div>
</div>
<button onclick="submitQuiz()">Submit Quiz</button>
<div class="result" id="result"></div>
</div>
<script>
function submitQuiz() {
let score = 0;
// Check question 1
const q1 = document.querySelector('input[name="q1"]:checked');
if (q1 && q1.value === 'Paris') {
score++;
}
// Check question 2
const q2 = document.querySelector('input[name="q2"]:checked');
if (q2 && q2.value === 'Mars') {
score++;
}
// Check question 3
const q3 = document.querySelector('input[name="q3"]:checked');
if (q3 && q3.value === 'Everest') {
score++;
}
// Display result
const resultDiv = document.getElementById('result');
if (score === 3) {
resultDiv.innerHTML = '🎉 Congratulations! You got all the answers correct! 🎉';
resultDiv.className = 'result correct';
} else {
resultDiv.innerHTML = `You got ${score}/3 correct. Try again!`;
resultDiv.className = 'result incorrect';
}
}
</script>
</body>
</html>