Skip to content

Commit 5a48302

Browse files
authored
Merge pull request #14 from sanghaibiraj/main
feat: bihar tourism quiz section
2 parents da100b8 + b403348 commit 5a48302

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[
2+
{
3+
"id": "q1",
4+
"question": "Where did Lord Buddha attain enlightenment?",
5+
"options": [
6+
{ "value": "bodh", "label": "Bodh Gaya" },
7+
{ "value": "rajgir", "label": "Rajgir" },
8+
{ "value": "vaishali", "label": "Vaishali" }
9+
],
10+
"answer": "bodh"
11+
},
12+
{
13+
"id": "q2",
14+
"question": "Which ancient university in Bihar is a UNESCO World Heritage Site?",
15+
"options": [
16+
{ "value": "takshashila", "label": "Takshashila" },
17+
{ "value": "nalanda", "label": "Nalanda" },
18+
{ "value": "vikramshila", "label": "Vikramshila" }
19+
],
20+
"answer": "nalanda"
21+
},
22+
{
23+
"id": "q3",
24+
"question": "The festival where devotees worship the Sun God is:",
25+
"options": [
26+
{ "value": "chhath", "label": "Chhath Puja" },
27+
{ "value": "holi", "label": "Holi" },
28+
{ "value": "diwali", "label": "Diwali" }
29+
],
30+
"answer": "chhath"
31+
},
32+
{
33+
"id": "q4",
34+
"question": "The capital city of Bihar is:",
35+
"options": [
36+
{ "value": "gaya", "label": "Gaya" },
37+
{ "value": "patna", "label": "Patna" },
38+
{ "value": "muzaffarpur", "label": "Muzaffarpur" }
39+
],
40+
"answer": "patna"
41+
},
42+
{
43+
"id": "q5",
44+
"question": "The wildlife reserve in West Champaran is:",
45+
"options": [
46+
{ "value": "valmiki", "label": "Valmiki Tiger Reserve" },
47+
{ "value": "kuno", "label": "Kuno National Park" },
48+
{ "value": "kaziranga", "label": "Kaziranga National Park" }
49+
],
50+
"answer": "valmiki"
51+
}
52+
]

bihar-culture-landing/script.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ document.addEventListener('DOMContentLoaded', function() {
88
initInteractiveElements();
99
initAccessibility();
1010
initProgressiveEnhancement();
11+
initQuiz(); // attach quiz logic if present
1112
});
1213

1314
// Navigation enhancements
@@ -288,6 +289,74 @@ function initProgressiveEnhancement() {
288289
}
289290
}
290291

292+
// Quiz initialization and logic
293+
function initQuiz() {
294+
const form = document.getElementById('bihar-quiz');
295+
if (!form) return;
296+
const result = document.getElementById('quiz-result');
297+
const container = document.getElementById('quiz-questions');
298+
if (!container) return;
299+
300+
fetch('quiz_questions.json')
301+
.then(res => res.json())
302+
.then(questions => {
303+
renderQuizQuestions(container, questions);
304+
305+
const answers = Object.fromEntries(questions.map(q => [q.id, q.answer]));
306+
307+
form.addEventListener('submit', function (e) {
308+
e.preventDefault();
309+
let score = 0;
310+
for (const [q, correct] of Object.entries(answers)) {
311+
const group = form.elements[q];
312+
if (group && group.value === correct) score++;
313+
}
314+
315+
let message = '';
316+
if (score === 5) message = 'Incredible! You’re a Bihar Boss!';
317+
else if (score >= 4) message = 'Great job! Bhojpuri Bravo!';
318+
else if (score >= 3) message = 'Nice! You’re on the Patna path.';
319+
else if (score >= 2) message = 'Not bad! Keep exploring Bihar.';
320+
else message = 'Time to tour Bihar’s wonders!';
321+
322+
if (result) result.textContent = 'You scored ' + score + '/5. ' + message;
323+
});
324+
})
325+
.catch(err => {
326+
console.error('Failed to load quiz questions:', err);
327+
if (result) result.textContent = 'Unable to load quiz. Please try again later.';
328+
});
329+
330+
form.addEventListener('reset', function () {
331+
if (result) result.textContent = '';
332+
});
333+
}
334+
335+
// Render quiz questions dynamically
336+
function renderQuizQuestions(container, questions) {
337+
container.innerHTML = '';
338+
questions.forEach((q, qi) => {
339+
const fs = document.createElement('fieldset');
340+
const legend = document.createElement('legend');
341+
legend.textContent = (qi + 1) + ') ' + q.question;
342+
fs.appendChild(legend);
343+
344+
q.options.forEach((opt, oi) => {
345+
const label = document.createElement('label');
346+
const input = document.createElement('input');
347+
input.type = 'radio';
348+
input.name = q.id;
349+
input.value = opt.value;
350+
if (oi === 0) input.required = true; // require a choice per group
351+
label.appendChild(input);
352+
label.append(' ' + opt.label);
353+
fs.appendChild(label);
354+
});
355+
356+
container.appendChild(fs);
357+
});
358+
}
359+
291360
// Utility functions for future enhancements
292361
const BiharCulture = {
293362
// Notification system

bihar-culture-landing/tourism.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,25 @@ <h2>Rajgir</h2>
3434
<h2>Valmiki Tiger Reserve</h2>
3535
<p>A natural reserve in West Champaran for wildlife lovers.</p>
3636
</section>
37+
38+
<section id="quiz">
39+
<h2>Quick Quiz: Bihar’s history, culture, and landmarks</h2>
40+
<form id="bihar-quiz">
41+
<div id="quiz-questions"></div>
42+
43+
<div class="quiz-actions">
44+
<button type="submit">Submit</button>
45+
<button type="reset">Reset</button>
46+
</div>
47+
</form>
48+
<div id="quiz-result" role="status" aria-live="polite"></div>
49+
</section>
3750
</main>
3851

3952
<footer>
4053
<p>Contributors can add more tourist spots!</p>
4154
</footer>
55+
56+
<script src="script.js"></script>
4257
</body>
4358
</html>

package-lock.json

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)