Ответ:
Ниже — готовая программа на HTML и JavaScript. Сохраните код в файл quiz.html и откройте его в браузере.
<!doctype html>
<html lang='ru'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Викторина по географии</title>
<style>
body { font-family: sans-serif; max-width: 700px; margin: 2rem auto; padding: 0 1rem; }
button { display: block; margin: .5rem 0; padding: .7rem; cursor: pointer; }
#feedback { font-weight: bold; }
</style>
</head>
<body>
<h1>Викторина по географии</h1>
<p id='progress'></p>
<h2 id='question'></h2>
<div id='options'></div>
<p id='feedback' aria-live='polite'></p>
<button id='next' hidden>Следующий вопрос</button>
<div id='result'></div>
<script>
const questions = [
{ text: 'Какой океан самый большой?', options: ['Атлантический', 'Тихий', 'Индийский', 'Северный Ледовитый'], correct: 1 },
{ text: 'Какой город является столицей Австралии?', options: ['Сидней', 'Мельбурн', 'Канберра', 'Перт'], correct: 2 },
{ text: 'Какая река протекает через Египет?', options: ['Нил', 'Амазонка', 'Волга', 'Дунай'], correct: 0 },
{ text: 'На каком материке находится Бразилия?', options: ['Африка', 'Южная Америка', 'Азия', 'Европа'], correct: 1 },
{ text: 'На какие полушария экватор делит Землю?', options: ['Западное и Восточное', 'Северное и Южное', 'Материковое и океаническое', 'Внутреннее и внешнее'], correct: 1 }
];
let current = 0;
let score = 0;
const questionEl = document.getElementById('question');
const optionsEl = document.getElementById('options');
const feedbackEl = document.getElementById('feedback');
const progressEl = document.getElementById('progress');
const nextButton = document.getElementById('next');
const resultEl = document.getElementById('result');
function showQuestion() {
if (current >= questions.length) {
const percent = Math.round(score / questions.length * 100);
questionEl.textContent = 'Викторина завершена';
progressEl.textContent = '';
optionsEl.innerHTML = '';
feedbackEl.textContent = '';
nextButton.hidden = true;
resultEl.textContent = 'Результат: ' + score + ' из ' + questions.length + ' (' + percent + '%).';
return;
}
const item = questions[current];
progressEl.textContent = 'Вопрос ' + (current + 1) + ' из ' + questions.length;
questionEl.textContent = item.text;
feedbackEl.textContent = '';
nextButton.hidden = true;
optionsEl.innerHTML = '';
item.options.forEach(function (option, index) {
const button = document.createElement('button');
button.textContent = option;
button.addEventListener('click', function () {
const buttons = optionsEl.querySelectorAll('button');
buttons.forEach(function (b) { b.disabled = true; });
if (index === item.correct) {
score += 1;
feedbackEl.textContent = 'Правильно!';
} else {
feedbackEl.textContent = 'Неправильно. Правильный ответ: ' + item.options[item.correct] + '.';
}
nextButton.hidden = false;
});
optionsEl.appendChild(button);
});
}
nextButton.addEventListener('click', function () {
current += 1;
showQuestion();
});
showQuestion();
</script>
</body>
</html>