Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions bihar-culture-landing/quiz_questions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"id": "q1",
"question": "Where did Lord Buddha attain enlightenment?",
"options": [
{ "value": "bodh", "label": "Bodh Gaya" },
{ "value": "rajgir", "label": "Rajgir" },
{ "value": "vaishali", "label": "Vaishali" }
],
"answer": "bodh"
},
{
"id": "q2",
"question": "Which ancient university in Bihar is a UNESCO World Heritage Site?",
"options": [
{ "value": "takshashila", "label": "Takshashila" },
{ "value": "nalanda", "label": "Nalanda" },
{ "value": "vikramshila", "label": "Vikramshila" }
],
"answer": "nalanda"
},
{
"id": "q3",
"question": "The festival where devotees worship the Sun God is:",
"options": [
{ "value": "chhath", "label": "Chhath Puja" },
{ "value": "holi", "label": "Holi" },
{ "value": "diwali", "label": "Diwali" }
],
"answer": "chhath"
},
{
"id": "q4",
"question": "The capital city of Bihar is:",
"options": [
{ "value": "gaya", "label": "Gaya" },
{ "value": "patna", "label": "Patna" },
{ "value": "muzaffarpur", "label": "Muzaffarpur" }
],
"answer": "patna"
},
{
"id": "q5",
"question": "The wildlife reserve in West Champaran is:",
"options": [
{ "value": "valmiki", "label": "Valmiki Tiger Reserve" },
{ "value": "kuno", "label": "Kuno National Park" },
{ "value": "kaziranga", "label": "Kaziranga National Park" }
],
"answer": "valmiki"
}
]
69 changes: 69 additions & 0 deletions bihar-culture-landing/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ document.addEventListener('DOMContentLoaded', function() {
initInteractiveElements();
initAccessibility();
initProgressiveEnhancement();
initQuiz(); // attach quiz logic if present
});

// Navigation enhancements
Expand Down Expand Up @@ -288,6 +289,74 @@ function initProgressiveEnhancement() {
}
}

// Quiz initialization and logic
function initQuiz() {
const form = document.getElementById('bihar-quiz');
if (!form) return;
const result = document.getElementById('quiz-result');
const container = document.getElementById('quiz-questions');
if (!container) return;

fetch('quiz_questions.json')
.then(res => res.json())
.then(questions => {
renderQuizQuestions(container, questions);

const answers = Object.fromEntries(questions.map(q => [q.id, q.answer]));

form.addEventListener('submit', function (e) {
e.preventDefault();
let score = 0;
for (const [q, correct] of Object.entries(answers)) {
const group = form.elements[q];
if (group && group.value === correct) score++;
}

let message = '';
if (score === 5) message = 'Incredible! You’re a Bihar Boss!';
else if (score >= 4) message = 'Great job! Bhojpuri Bravo!';
else if (score >= 3) message = 'Nice! You’re on the Patna path.';
else if (score >= 2) message = 'Not bad! Keep exploring Bihar.';
else message = 'Time to tour Bihar’s wonders!';

if (result) result.textContent = 'You scored ' + score + '/5. ' + message;
});
})
.catch(err => {
console.error('Failed to load quiz questions:', err);
if (result) result.textContent = 'Unable to load quiz. Please try again later.';
});

form.addEventListener('reset', function () {
if (result) result.textContent = '';
});
}

// Render quiz questions dynamically
function renderQuizQuestions(container, questions) {
container.innerHTML = '';
questions.forEach((q, qi) => {
const fs = document.createElement('fieldset');
const legend = document.createElement('legend');
legend.textContent = (qi + 1) + ') ' + q.question;
fs.appendChild(legend);

q.options.forEach((opt, oi) => {
const label = document.createElement('label');
const input = document.createElement('input');
input.type = 'radio';
input.name = q.id;
input.value = opt.value;
if (oi === 0) input.required = true; // require a choice per group
label.appendChild(input);
label.append(' ' + opt.label);
fs.appendChild(label);
});

container.appendChild(fs);
});
}

// Utility functions for future enhancements
const BiharCulture = {
// Notification system
Expand Down
15 changes: 15 additions & 0 deletions bihar-culture-landing/tourism.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,25 @@ <h2>Rajgir</h2>
<h2>Valmiki Tiger Reserve</h2>
<p>A natural reserve in West Champaran for wildlife lovers.</p>
</section>

<section id="quiz">
<h2>Quick Quiz: Bihar’s history, culture, and landmarks</h2>
<form id="bihar-quiz">
<div id="quiz-questions"></div>

<div class="quiz-actions">
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</div>
</form>
<div id="quiz-result" role="status" aria-live="polite"></div>
</section>
</main>

<footer>
<p>Contributors can add more tourist spots!</p>
</footer>

<script src="script.js"></script>
</body>
</html>
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading