I'm rather new to HTML/CSS/JS... I've seen functions to randomize quiz questions however can't make any of the solutions work with the code I already have.
I would really appreciate someone showing me a way to randomize the questions displayed. And would also like a brief description on why it works.
This is not classwork/coursework... I'm trying to create a quiz for a series of classes I'm taking for work.
Thank you in advance :)
This code works but does not randomize the questions. Questions are store in 'questions.js' and look like this:
questions.js
{
numb: 7,
question: "The property tax is an ______ ______ tax, meaning it is based on value.",
answer: "B. ad valorem",
options: [
"A. carpe diem",
"B. ad valorem",
"C. vino veritas",
"D. non verba"
]
},
script.js
const questionText = document.querySelector('.question-text');
// questionText.textContent = `${questions[index].numb}. ${questions[index].question}`;
questionText.textContent = `${questions[index].question}`;
let optionTag = `<div class="option"><span>${questions[index].options[0]}</span></div>
<div class="option"><span>${questions[index].options[1]}</span></div>
<div class="option"><span>${questions[index].options[2]}</span></div>
<div class="option"><span>${questions[index].options[3]}</span></div>`;```