JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Aplikacja quizu</title>
<meta name="keywords" content="aplikacja, quiz, pytania, odpowiedzi">
<meta name="description" content="Podstawowa aplikacja do quizu">
<link rel="stylesheet" href="style.css">
<script src="index.js" defer></script>
</head>
<body>
<div class="content">
<div class="content-quiz">
<div class="content-quiz-questions">
<h2 id="header-question"></h2>
</div>
<div class="content-quiz-answers">
<ul>
<li>
<input type="radio" id="label-answer_A" name="answer" class="answer">
<label id="a" for="label-answer_A"></label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="label-answer_B" name="answer" class="answer">
<label id="b" for="label-answer_B"></label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="label-answer_C" name="answer" class="answer">
<label id="c" for="label-answer_C"></label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="label-answer_D" name="answer" class="answer">
<label id="d" for="label-answer_D"></label>
</li>
</ul>
</div>
</div>
<button type="submit" class="btn-submit">Submit</button>
</div>
</body>
</html>
JavaScript
const headerQuestion = document.getElementById('header-question');
let oldQuestionIndex = -1;
const labelAnswerA = document.getElementById('label-answer_A');
const labelAnswerB = document.getElementById('label-answer_B');
const labelAnswerC = document.getElementById('label-answer_C');
const labelAnswerD = document.getElementById('label-answer_D');
let arrAnswerVaranty = ['a', 'b', 'c', 'd'];
const btnSubmit = document.querySelector('.btn-submit');
const quizArr = [{
question: 'What is the most used programming language in 2019?',
answers: ['Java', 'C', 'Python', 'JS']
},
{
question: 'Who is the President of US?',
answers: ['Florin Pop', 'Joe Biden', 'Ivan Saldano', 'Mihai Andrei']
},
{
question: 'What does HTML stand for?',
answers: [
'Hypertext Markup Language',
'Cascading Style Sheet',
'Jason Object Notation',
'Helicopters Terminals Motorboats Lamborgini'
]
},
{
question: 'What year was JavaScript launched?',
answers: ['1996', '1995', '1994', 'none of the above']
}
];
function getRandomQuestion() {
let currentRandomIndex;
do {
currentRandomIndex = Math.floor(Math.random() * answers.length);
} while (currentRandomIndex === oldQuestionIndex);
oldQuestionIndex = currentRandomIndex;
}
function getRandomVariants() {}
function showRandomQuestion() {}
btnSubmit.addEventListener('click', function() {
showRandomQuestions();
});
showRandomQuestion();