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-questions">Question</h2>
</div>
<div class="content-quiz-answers">
<ul>
<li>
<input type="radio" id="answer_a" name="answer" class="answer">
<label id="a" for="answer_a">Question</label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="answer_b" name="answer" class="answer">
<label id="b" for="answer_b">Question</label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="answer_c" name="answer" class="answer">
<label id="c" for="answer_c">Question</label>
</li>
</ul>
<ul>
<li>
<input type="radio" id="answer_d" name="answer" class="answer">
<label id="d" for="answer_d">Question</label>
</li>
</ul>
</div>
</div>
<div class="btn-quiz">
<button type="submit">Wyślij</button>
</div>
</div>
</body>
</html>
JavaScript
const headQuestions = document.getElementById('header-questions');
headQuestions.innerHTML = questQuiz();
const btnSubmit = document.querySelector('button');
function questQuiz() {
const questArr = [
'What is the most used programming language in 2019?',
'Who is the President of US?',
'What does HTML stand for?',
'What year was JavaScript launched?'
];
let emptyStr = '';
for (let i = questArr.length - 1; i >= 0; i--) {
emptyStr = questArr[i];
}
return emptyStr;
}
const answerA = document.getElementById('a');
answerA.innerHTML = answersQuiz();
const answerB = document.getElementById('b');
answerB.innerHTML = answersQuiz();
const answerC = document.getElementById('c');
answerC.innerHTML = answersQuiz();
const answerD = document.getElementById('d');
answerD.innerHTML = answersQuiz();
function answersQuiz() {
const answers = [ 'Java', 'C', 'Python', 'JS' ];
for (const id of [ 'a', 'b', 'c', 'd' ]) {
const element = document.getElementById(id);
for (let i = 1; i < answers.length; i++) {
var answerIndex = Math.floor(Math.random() * i);
}
element.innerText = answers[answerIndex];
answers.splice(answerIndex, 1);
}
}