123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- const qBase = [
- {
- question: 'Какой сейчас год?',
- a: '1000',
- b: '2000',
- c: '2001',
- d: '2021',
- answer: 'a'
- },
- {
- question: 'Самый распространенный язык программирования?',
- a: 'java script',
- b: 'java',
- c: 'python',
- d: 'c++',
- answer: 'b'
- },
- {
- question: 'Как расшифровывается аббревиатура HTML?',
- a: 'hello to media line',
- b: 'hypertext media language',
- c: 'hypertext markup language',
- d: 'hydro throne mobile loft',
- answer: 'c'
- },
- {
- question: 'Когда приходит Дед Мороз?',
- a: 'никогда',
- b: 'он и не уходил',
- c: 'в ночь перед Рождеством',
- d: 'в Новогоднюю ночь',
- answer: 'd'
- },
- ];
- const question = document.getElementById('question');
- const questionA = document.getElementById('guess_a');
- const questionB = document.getElementById('guess_b');
- const questionC = document.getElementById('guess_c');
- const questionD = document.getElementById('guess_d');
- const submitBtn = document.getElementById('submit');
- const result = document.getElementById('result');
- const radioButtons = document.querySelectorAll("input[type='radio']");
- let currentQuestion = 0;
- let score = 0;
- loadQuestion();
- function loadQuestion()
- {
- question.textContent = qBase[currentQuestion].question;
- questionA.textContent = qBase[currentQuestion].a;
- questionB.textContent = qBase[currentQuestion].b;
- questionC.textContent = qBase[currentQuestion].c;
- questionD.textContent = qBase[currentQuestion].d;
- }
- function getSelectedRadioButtons()
- {
- let answer_id;
- radioButtons.forEach((button) =>
- {
- if (button.checked)
- answer_id = button.id;
- });
- return answer_id;
- }
- function deselectRadioButtons()
- {
- radioButtons.forEach((button) => { button.checked = false; });
- }
- submitBtn.addEventListener('click', () =>
- {
- const answer_id = getSelectedRadioButtons();
- if (answer_id == qBase[currentQuestion].answer)
- {
- score++;
- }
- if (currentQuestion >= (qBase.length - 1))
- {
- currentQuestion = 0;
- result.innerHTML = `<h1 style="font-size: 24px">Your score is: ${score} of ${qBase.length}</h1>`;
- }
- else
- {
- currentQuestion++;
- }
- deselectRadioButtons();
- loadQuestion();
- });
|