Вопросы и логика: 10 вопросов, подсчёт очков, экран результата
This commit is contained in:
@@ -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
|
||||
}
|
||||
];
|
||||
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user