-
Notifications
You must be signed in to change notification settings - Fork 217
/
quiz.html
357 lines (314 loc) · 11.9 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Krishna Quiz</title>
<!-- <link rel="stylesheet" href="styles.css"> -->
<style>
/* CSS Styles */
body {
font-family: Arial, sans-serif;
background-color: var(--primary-color); /* Light blue background */
color: var(--question-color); /* Dark blue text */
margin: 0;
padding: 20px;
text-align: center;
/* display: flex;
justify-content: center;
align-items: center;
min-height: 100vh; */
}
h1 {
color: var(--heading-color); /* Krishna's blue */
margin: 20px 0;
font-size: 36px; /* Larger heading */
/* text-align: center; */
}
#quizContainer {
background-color: var(--quizContainer-color); /* Light background color */
border-radius: 10px;
padding: 30px; /* Increased padding */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: inline-block;
margin: 20px auto; /* Center the form */
max-width: 600px; /* Limit width of quiz container */
}
p {
font-size: 24px; /* Larger question text */
/* color: #b0bec5;
margin-bottom: 20px; */
}
.optionBtn {
display: block;
background-color: var(--opnbtn-color); /* Yellow button */
border: none;
padding: 15px 30px; /* Increased padding */
border-radius: 5px;
cursor: pointer;
font-size: 18px; /* Larger font size */
margin: 10px auto; /* Center buttons */
transition: background-color 0.3s ease;
width: 100%; /* Full width */
}
.optionBtn:hover {
background-color: var(--opnbtnHover-color) !important; /* Darker yellow on hover */
}
#result {
margin-top: 20px;
font-size: 22px; /* Larger result text */
color: var(--result-color); /* Krishna's blue */
}
#score {
font-size: 22px; /* Larger score text */
color: var(--score-color); /* Dark blue */
/* margin-top: 20px; */
}
#homeBtn {
background-color: #4caf50; /* Green button */
border: none;
padding: 15px 30px;
border-radius: 5px;
cursor: pointer;
font-size: 18px;
margin-top: 20px;
color: white;
/* transition: background-color 0.3s; */
}
#homeBtn:hover {
background-color: #45a049; /* Darker green on hover */
}
#nextBtn {
background-color: #2196F3; /* Blue button */
border: none;
padding: 15px 30px;
border-radius: 5px;
cursor: pointer;
font-size: 18px;
margin-top: 20px;
color: white;
display: none; /* Initially hidden */
/* transition: background-color 0.3s; */
}
#nextBtn:hover {
background-color: #1976D2; /* Darker blue on hover */
}
/* Additional styles for mobile responsiveness */
@media (max-width: 600px) {
h1 {
font-size: 28px;
}
p {
font-size: 20px;
}
.optionBtn {
font-size: 16px;
padding: 10px;
}
#homeBtn, #nextBtn {
font-size: 16px;
padding: 10px;
}
}
#icon{
width: 30px;
cursor: pointer;
position: absolute;
right: 50px;
top: 50px;
}
.correct {
background-color: var(--correct-color) !important;
}
.incorrect {
background-color: var(--incorrect-color) !important;
}
:root{
--primary-color: #f0f8ff;
--heading-color: #3f51b5;
--quizContainer-color: #e3f2fd;
--question-color: #2e4a7e;
--opnbtn-color: #ffeb3b;
--opnbtnHover-color: #ffc107;
--correct-color: green !important;
--incorrect-color: red !important;
--result-color: #3f51b5;
--score-color: #2e4a7e;
}
/* =================================================================================== */
/* General Body */
/* ==================================================================================== */
.dark-theme{
background-image: url(https://www.hitaambrish.com/stat/img/home/Gallery_Bg.jpg);
--heading-color: gold;
--quizContainer-color: transparent;
--question-color: gold;
--result-color: gold;
--score-color: aqua;
}
/* customization for some borders */
.dark-theme #quizContainer{
border: 2px solid aqua;
box-shadow: 0px 0px 10px 3px aqua;
}
.dark-theme .optionBtn {
background-color: rgb(28, 59, 137) !important;
/* light mode colors becoming higher specifity so important is required */
border: 2px solid aqua;
box-shadow: 3px 3px 4px aqua;
color: white;
}
.dark-theme .optionBtn:hover{
background-color: rgb(21, 46, 109) !important;
}
/* ============================================ */
.navigation-buttons {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.quiz-header h1 {
color: var(--heading-color); /* Krishna's blue */
color: var(--heading-color); /* Krishna's blue */
margin: 20px 0;
font-size: 36px;
font-size: 2rem;
/* color: #4b72e0; */
margin-bottom: 20px;
font-weight: bold;
text-shadow: 1px 1px 2px #cdd6f3;
}
</style>
</head>
<body>
<img src="images/moon.png" id="icon">
<!-- <h1>Krishna Quiz</h1> -->
<div id="quizContainer">
<header class="quiz-header">
<h1>Krishna Quiz</h1>
</header>
<p id="question"></p>
<button class="optionBtn" id="option1" onclick="checkAnswer('option1')"></button>
<button class="optionBtn" id="option2" onclick="checkAnswer('option2')"></button>
<button class="optionBtn" id="option3" onclick="checkAnswer('option3')"></button>
<button class="optionBtn" id="option4" onclick="checkAnswer('option4')"></button>
<div id="result"></div>
<div id="score"></div>
<div class="navigation-buttons">
<button id="nextBtn" onclick="nextQuestion()">Next</button>
<!-- <br> -->
<button id="homeBtn" onclick="goHome()">Home</button>
</div>
</div>
<script>
// JavaScript for quiz functionality
const quizData = [
{
question: "What is the name of Krishna's father?",
options: ["Vasudeva", "Nanda", "Yashoda", "Kamsa"],
answer: "Vasudeva"
},
{
question: "Which river did Krishna cross during his childhood?",
options: ["Ganges", "Yamuna", "Saraswati", "Godavari"],
answer: "Yamuna"
},
{
question: "What instrument does Krishna famously play?",
options: ["Flute", "Veena", "Tabla", "Harmonium"],
answer: "Flute"
},
{
question: "What is Krishna's favorite food?",
options: ["Butter", "Rice", "Pulses", "Fruits"],
answer: "Butter"
},
{
question: "Who is Krishna's beloved?",
options: ["Radharani", "Sita", "Draupadi", "Laxmi"],
answer: "Radharani"
},
{
question: "What is the name of Krishna's childhood friend?",
options: ["Arjuna", "Balarama", "Yashoda", "Draupadi"],
answer: "Balarama"
},
{
question: "Which demon did Krishna defeat during his childhood?",
options: ["Putana", "Kamsa", "Trinavarta", "Bakasura"],
answer: "Putana"
},
{
question: "What is Krishna's role in the Mahabharata?",
options: ["Warrior", "Charioteer", "King", "Adviser"],
answer: "Charioteer"
}
];
let currentQuestionIndex = 0;
let score = 0;
function loadQuestion() {
const currentQuestion = quizData[currentQuestionIndex];
document.getElementById("question").innerText = currentQuestion.question;
document.getElementById("option1").innerText = currentQuestion.options[0];
document.getElementById("option2").innerText = currentQuestion.options[1];
document.getElementById("option3").innerText = currentQuestion.options[2];
document.getElementById("option4").innerText = currentQuestion.options[3];
document.getElementById("result").innerText = ""; // Clear previous result
// Reset button colors
const options = document.querySelectorAll(".optionBtn");
const root = document.documentElement;
const color = getComputedStyle(root).getPropertyValue(`--opnbtn-color`).trim();
options.forEach(option => {
option.style.backgroundColor = color; // Reset to default
option.disabled = false; // Enable buttons
});
// Hide Next button initially
document.getElementById("nextBtn").style.display = "none";
}
function checkAnswer(selectedOption) {
const selectedAnswer = document.getElementById(selectedOption).innerText;
const correctAnswer = quizData[currentQuestionIndex].answer;
const options = document.querySelectorAll(".optionBtn");
options.forEach(option => {
option.disabled = true; // Disable all option buttons
if (option.innerText === correctAnswer) {
option.style.setProperty("background-color", "green", "important"); // Green for correct
}
if (option.innerText === selectedAnswer && selectedAnswer !== correctAnswer) {
option.style.setProperty("background-color", "red", "important"); // Red for wrong
}
});
// Update result message
if (selectedAnswer === correctAnswer) {
score++;
document.getElementById("result").innerText = "✔️ Correct! The answer is: " + correctAnswer;
} else {
document.getElementById("result").innerText = "❌ Wrong! The correct answer is: " + correctAnswer;
}
// Show Next button
document.getElementById("nextBtn").style.display = "inline-block";
}
function nextQuestion() {
currentQuestionIndex++;
if (currentQuestionIndex < quizData.length) {
loadQuestion();
} else {
showFinalResult();
}
}
function showFinalResult() {
document.getElementById("quizContainer").style.display = "none";
document.getElementById("result").innerText = "Quiz Finished!";
document.getElementById("score").innerText = `Your score: ${score} out of ${quizData.length}`;
document.getElementById("nextBtn").style.display = "none"; // Hide Next button
}
function goHome() {
// Implement the home functionality (e.g., redirecting to home page)
window.location.href = "index.html"; // Replace with your home page URL
}
// Load the first question on page load
loadQuestion();
</script>
<script src="script.js"></script>
</body>
</html>