JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" type="text/css" href="Tyyli.css">
<title>Pääsykoe Apu</title>
</head>
<body>
<h1>Pääsykoe kysymyksiä</h1>
<div class="quiz-container">
<div id="quiz"></div>
</div>
<button id="previous">Edellinen kysymys</button>
<button id="next">Seuraava kysymys</button>
<button id="submit">Valmis</button>
<div id="results"></div>
</body>
</html>
JavaScript
(function runAll(){
function shuffle(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
let myQuestions = [
{
question: "Esimerkki kysymys1",
answers: {
a: "Oikein",
b: "Väärin"
},
correctAnswer: "a"
},
{
question: "Esimerkki kysymys2",
answers: {
a: "Oikein",
b: "Väärin"
},
correctAnswer: "b"
},
{
question: "Esimerkki kysymys3",
answers: {
a: "Oikein",
b: "Väärin"
},
correctAnswer: "a"
}
];
myQuestions = shuffle(myQuestions);
function buildQuiz(){
// we'll need a place to store the HTML output
const output = [];
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// we'll want to store the list of answer choices
const answers = [];
// and for each available answer...
for (var letter in currentQuestion.answers) {
// ...add an HTML radio button
answers.push(
`<label>
<input type="radio" name="question${questionNumber}"...