mirror of
https://github.com/olehomelchenko/minivlat-local-ua.git
synced 2025-12-21 13:12:23 +00:00
Randomize quiz question order and store ordinal number for each question
This commit is contained in:
@@ -56,6 +56,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
throw new Error('Invalid quiz data or version');
|
||||
}
|
||||
questions = data.quizzes[version].questions;
|
||||
questions = shuffleArray(questions); // Randomize the order of questions
|
||||
displayQuestion();
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -63,6 +64,15 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
quizContainer.innerHTML = '<p>Error loading quiz. Please try again later.</p>';
|
||||
});
|
||||
|
||||
// Function to shuffle an array
|
||||
function shuffleArray(array) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function displayQuestion() {
|
||||
if (!questions || currentQuestionIndex >= questions.length) {
|
||||
showResults();
|
||||
@@ -162,6 +172,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
correctAnswer: currentQuestion.answer,
|
||||
isCorrect: isCorrect,
|
||||
questionIndex: currentQuestionIndex,
|
||||
ordinalNumber: currentQuestionIndex + 1, // Store the ordinal number of the question
|
||||
timestamp: new Date().toISOString(),
|
||||
timeSpent: 25000 - timeLeft, // Time spent in milliseconds
|
||||
chartType: currentQuestion.chart,
|
||||
|
||||
Reference in New Issue
Block a user