const questions = [ { question: "Какой витамин вырабатывается под воздействием солнечного света?", options: ["Витамин A", "Витамин C", "Витамин D", "Витамин E"], correctAnswer: "Витамин D" }, { question: "Какой орган человека вырабатывает витамин D под воздействием солнца?", options: ["Печень", "Кожа", "Почки", "Сердце"], correctAnswer: "Кожа" }, { question: "Какой продукт богат витамином D?", options: ["Яблоки", "Рыбий жир", "Картофель", "Хлеб"], correctAnswer: "Рыбий жир" }, { question: "Какой витамин D помогает усваивать кальций?", options: ["Витамин D1", "Витамин D2", "Витамин D3", "Витамин D4"], correctAnswer: "Витамин D3" } ]; let currentQuestionIndex = 0; let correctAnswersCount = 0; const celestialBody = document.getElementById('celestial-body'); const questionElement = document.getElementById('question'); const optionsElement = document.getElementById('options'); const resultElement = document.getElementById('result'); function showQuestion() { const currentQuestion = questions[currentQuestionIndex]; questionElement.textContent = currentQuestion.question; optionsElement.innerHTML = ''; currentQuestion.options.forEach(option => { const button = document.createElement('button'); button.textContent = option; button.addEventListener('click', () => checkAnswer(option)); optionsElement.appendChild(button); }); } function checkAnswer(selectedOption) { const currentQuestion = questions[currentQuestionIndex]; if (selectedOption === currentQuestion.correctAnswer) { correctAnswersCount++; resultElement.textContent = "Правильно!"; } else { resultElement.textContent = "Неправильно. Попробуйте еще раз."; } currentQuestionIndex++; if (currentQuestionIndex < questions.length) { showQuestion(); } else { endGame(); } updateCelestialBody(); } function updateCelestialBody() { const progress = correctAnswersCount / questions.length; celestialBody.style.opacity = 1 - progress; if (progress >= 1) { celestialBody.src = "sun.png"; } } function endGame() { questionElement.textContent = "Игра завершена!"; optionsElement.innerHTML = ''; resultElement.textContent = `Вы ответили правильно на ${correctAnswersCount} из ${questions.length} вопросов.`; } showQuestion();