const quizData = [ { question: "Столица Беларуси — это…", options: ["Гродно", "Минск", "Витебск", "Гомель"], answer: 1, fact: "Минск — самый большой город страны и её главный культурный центр.", imagePath: "assets/pasted-20260305-185724-631e7f99.webp", imageAlt: "Панорама Минска" }, { question: "Какие цвета есть на флаге Беларуси?", options: ["Синий и жёлтый", "Белый и красный", "Красный и зелёный", "Белый и зелёный"], answer: 2, fact: "Красный и зелёный — основные цвета флага, а сбоку есть орнамент.", imagePath: "assets/images/quiz/q02-flag.jpg", imageAlt: "Флаг Беларуси" }, { question: "Самое большое озеро Беларуси называется…", options: ["Нарочь", "Свитязь", "Дривяты", "Кромань"], answer: 0, fact: "Озеро Нарочь — любимое место отдыха и часть Нарачанского парка.", imagePath: "assets/pasted-20260305-185926-dd9a5c42.webp", imageAlt: "Озеро в Беларуси" }, { question: "Национальный символ животного Беларуси — это…", options: ["Зубр", "Лось", "Медведь", "Лиса"], answer: 0, fact: "Зубр — редкое и сильное животное, живёт в Беловежской пуще.", imagePath: "assets/images/quiz/q04-bison.jpg", imageAlt: "Зубр" }, { question: "Как называется главный заповедник Беларуси?", options: ["Беловежская пуща", "Березинский парк", "Браславские озёра", "Припятский парк"], answer: 0, fact: "Беловежская пуща — старинный лес, который охраняется ЮНЕСКО.", imagePath: "assets/pasted-20260305-190111-63cd8baa.jpg", imageAlt: "Лес Беловежской пущи" }, { question: "Какой город называют «северной столицей» Беларуси?", options: ["Витебск", "Гомель", "Брест", "Полоцк"], answer: 0, fact: "Витебск — родина художника Марка Шагала.", imagePath: "assets/images/quiz/q06-vitebsk.jpg", imageAlt: "Город Витебск" }, { question: "Белорусский народный инструмент с кнопками — это…", options: ["Цимбалы", "Скрипка", "Дудка", "Сопилка"], answer: 0, fact: "Цимбалы — струнный инструмент, по ним ударяют молоточками.", imagePath: "assets/images/quiz/q07-cimbaly.jpg", imageAlt: "Традиционный музыкальный инструмент" }, { question: "Какой замок стоит в городе Мир?", options: ["Мирский замок", "Несвижский замок", "Лидский замок", "Гродненский замок"], answer: 0, fact: "Мирский замок — объект Всемирного наследия ЮНЕСКО.", imagePath: "assets/images/quiz/q08-castle.jpg", imageAlt: "Мирский замок" }, { question: "Главная река Беларуси — это…", options: ["Западная Двина", "Днепр", "Нёман", "Припять"], answer: 1, fact: "Днепр проходит через южные регионы страны и впадает в Чёрное море.", imagePath: "assets/images/quiz/q09-river.jpg", imageAlt: "Река Днепр" }, { question: "Как называется традиционный белорусский узор на ткани?", options: ["Орнамент", "Гжель", "Петриковская роспись", "Хохлома"], answer: 0, fact: "Белорусский орнамент часто украшает флаг и народные костюмы.", imagePath: "assets/images/quiz/q10-ornament.jpg", imageAlt: "Белорусский орнамент" }, { question: "Самый древний город Беларуси — это…", options: ["Полоцк", "Минск", "Брест", "Могилёв"], answer: 0, fact: "Полоцк впервые упоминается в летописях в 862 году.", imagePath: "assets/images/quiz/q11-polotsk.jpg", imageAlt: "Город Полоцк" }, { question: "Как называется сладость из мёда и орехов, популярная в Беларуси?", options: ["Пастила", "Печенье", "Козинаки", "Зефир"], answer: 2, fact: "Козинаки часто готовят из мёда и орехов.", imagePath: "assets/images/quiz/q12-kozinaki.jpg", imageAlt: "Козинаки" } ]; const startBtn = document.getElementById("startQuizBtn"); const quizSection = document.getElementById("quiz"); const summarySection = document.getElementById("summary"); const progressEl = document.getElementById("questionProgress"); const questionText = document.getElementById("questionText"); const optionList = document.getElementById("optionList"); const totalQuestions = document.getElementById("totalQuestions"); const classScore = document.getElementById("classScore"); const revealBtn = document.getElementById("revealBtn"); const nextBtn = document.getElementById("nextBtn"); const answerArea = document.getElementById("answerArea"); const answerImage = document.getElementById("answerImage"); const correctAnswer = document.getElementById("correctAnswer"); const factText = document.getElementById("factText"); const answerResult = document.getElementById("answerResult"); const finalScore = document.getElementById("finalScore"); const summaryList = document.getElementById("summaryList"); const restartBtn = document.getElementById("restartBtn"); const state = { index: 0, score: 0, revealed: false, selectedOption: null }; totalQuestions.textContent = quizData.length.toString(); function renderQuestion() { const current = quizData[state.index]; progressEl.textContent = `Вопрос ${state.index + 1} из ${quizData.length}`; questionText.textContent = current.question; optionList.innerHTML = ""; current.options.forEach((option, idx) => { const li = document.createElement("li"); li.className = "option-item"; li.setAttribute("role", "button"); li.setAttribute("tabindex", "0"); li.dataset.index = String(idx); if (idx === state.selectedOption) { li.classList.add("option-item-selected"); } if (state.revealed) { if (idx === current.answer) { li.classList.add("option-item-correct"); } else if (idx === state.selectedOption) { li.classList.add("option-item-wrong"); } } li.innerHTML = `${String.fromCharCode(65 + idx)}${option}`; optionList.appendChild(li); }); classScore.textContent = state.score.toString(); answerArea.classList.toggle("d-none", !state.revealed); revealBtn.classList.toggle("d-none", state.revealed); nextBtn.classList.toggle("d-none", !state.revealed); revealBtn.disabled = state.selectedOption === null; if (state.revealed) { answerImage.src = current.imagePath; answerImage.alt = current.imageAlt; correctAnswer.textContent = current.options[current.answer]; factText.textContent = current.fact; answerResult.textContent = state.selectedOption === current.answer ? "Верно! +1 балл." : "Немного не так. В следующий раз получится!"; answerResult.className = `mt-3 mb-0 fw-semibold ${state.selectedOption === current.answer ? "text-success" : "text-danger"}`; } } function showSummary() { quizSection.classList.add("d-none"); summarySection.classList.remove("d-none"); finalScore.textContent = `${state.score} из ${quizData.length}`; summaryList.innerHTML = ""; quizData.forEach((item, idx) => { const div = document.createElement("div"); div.className = "summary-item"; div.innerHTML = ` ${item.imageAlt}

Вопрос ${idx + 1}: ${item.question}

Правильный ответ: ${item.options[item.answer]}

${item.fact}

`; summaryList.appendChild(div); }); } startBtn.addEventListener("click", () => { quizSection.classList.remove("d-none"); summarySection.classList.add("d-none"); state.index = 0; state.score = 0; state.revealed = false; state.selectedOption = null; renderQuestion(); quizSection.scrollIntoView({ behavior: "smooth" }); }); revealBtn.addEventListener("click", () => { if (state.selectedOption === null) return; const current = quizData[state.index]; if (state.selectedOption === current.answer) { state.score += 1; } state.revealed = true; renderQuestion(); }); nextBtn.addEventListener("click", () => { if (state.index < quizData.length - 1) { state.index += 1; state.revealed = false; state.selectedOption = null; renderQuestion(); } else { showSummary(); summarySection.scrollIntoView({ behavior: "smooth" }); } }); restartBtn.addEventListener("click", () => { state.index = 0; state.score = 0; state.revealed = false; state.selectedOption = null; summarySection.classList.add("d-none"); quizSection.classList.remove("d-none"); renderQuestion(); quizSection.scrollIntoView({ behavior: "smooth" }); }); optionList.addEventListener("click", (event) => { if (state.revealed) return; const option = event.target.closest(".option-item"); if (!option) return; state.selectedOption = Number(option.dataset.index); renderQuestion(); }); optionList.addEventListener("keydown", (event) => { if (state.revealed) return; if (event.key !== "Enter" && event.key !== " ") return; const option = event.target.closest(".option-item"); if (!option) return; event.preventDefault(); state.selectedOption = Number(option.dataset.index); renderQuestion(); });