From e3493e6fed271741712be94114e1cc6c5347bef9 Mon Sep 17 00:00:00 2001 From: mgeld Date: Mon, 13 Jul 2026 02:38:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0:=2010=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2,=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D1=81=D1=87=D1=91=D1=82=20=D0=BE=D1=87=D0=BA=D0=BE=D0=B2?= =?UTF-8?q?,=20=D1=8D=D0=BA=D1=80=D0=B0=D0=BD=20=D1=80=D0=B5=D0=B7=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D0=B0=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- questions.js | 53 +++++++++++++++++++++++++++++++++++++++++ quiz.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 questions.js create mode 100644 quiz.js diff --git a/questions.js b/questions.js new file mode 100644 index 0000000..9c068ad --- /dev/null +++ b/questions.js @@ -0,0 +1,53 @@ +// Вопросы викторины. Каждый вопрос: текст, 4 варианта, номер правильного (с нуля). +const QUESTIONS = [ + { + text: "Какая планета Солнечной системы самая большая?", + options: ["Земля", "Юпитер", "Сатурн", "Нептун"], + correct: 1 + }, + { + text: "Сколько минут в двух с половиной часах?", + options: ["120", "135", "150", "180"], + correct: 2 + }, + { + text: "Какой океан самый глубокий?", + options: ["Атлантический", "Индийский", "Северный Ледовитый", "Тихий"], + correct: 3 + }, + { + text: "Кто написал роман «Война и мир»?", + options: ["Достоевский", "Толстой", "Чехов", "Тургенев"], + correct: 1 + }, + { + text: "Какой газ растения поглощают из воздуха при фотосинтезе?", + options: ["Кислород", "Азот", "Углекислый газ", "Водород"], + correct: 2 + }, + { + text: "Столица Австралии — это…", + options: ["Сидней", "Мельбурн", "Канберра", "Брисбен"], + correct: 2 + }, + { + text: "Сколько сторон у шестиугольника?", + options: ["Пять", "Шесть", "Семь", "Восемь"], + correct: 1 + }, + { + text: "Какое море самое солёное на Земле?", + options: ["Чёрное", "Средиземное", "Красное", "Мёртвое"], + correct: 3 + }, + { + text: "В каком году человек впервые высадился на Луну?", + options: ["1957", "1961", "1969", "1975"], + correct: 2 + }, + { + text: "Как называется самая длинная река в мире?", + options: ["Амазонка", "Нил", "Янцзы", "Миссисипи"], + correct: 0 + } +]; diff --git a/quiz.js b/quiz.js new file mode 100644 index 0000000..77f87da --- /dev/null +++ b/quiz.js @@ -0,0 +1,67 @@ +// Логика викторины. Данные вопросов — в questions.js (массив QUESTIONS). +let idx = 0; +let score = 0; + +const scrStart = document.getElementById("screen-start"); +const scrQuiz = document.getElementById("screen-quiz"); +const scrResult = document.getElementById("screen-result"); + +document.getElementById("btn-start").addEventListener("click", start); +document.getElementById("btn-again").addEventListener("click", start); + +function start() { + idx = 0; + score = 0; + show(scrQuiz); + renderQ(); +} + +function renderQ() { + const q = QUESTIONS[idx]; + document.getElementById("progress").textContent = + "Вопрос " + (idx + 1) + " из " + QUESTIONS.length; + document.getElementById("q-text").textContent = q.text; + + const box = document.getElementById("q-options"); + box.innerHTML = ""; + q.options.forEach(function (opt, i) { + const b = document.createElement("button"); + b.textContent = opt; + b.addEventListener("click", function () { + chkAns(i); + }); + box.appendChild(b); + }); +} + +function chkAns(i) { + if (i === QUESTIONS[idx].correct) { + score++; + } + idx++; + if (idx < QUESTIONS.length) { + renderQ(); + } else { + showResult(); + } +} + +function showResult() { + show(scrResult); + document.getElementById("result-text").textContent = + "Правильных ответов: " + score + " из " + QUESTIONS.length + ". " + verdict(); +} + +function verdict() { + if (score === QUESTIONS.length) return "Идеально!"; + if (score >= 7) return "Отличный результат."; + if (score >= 4) return "Неплохо, но есть куда расти."; + return "Стоит попробовать ещё раз."; +} + +function show(screen) { + scrStart.classList.add("hidden"); + scrQuiz.classList.add("hidden"); + scrResult.classList.add("hidden"); + screen.classList.remove("hidden"); +}