mirror of
https://github.com/olehomelchenko/minivlat-local-ua.git
synced 2025-12-21 21:22:24 +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');
|
throw new Error('Invalid quiz data or version');
|
||||||
}
|
}
|
||||||
questions = data.quizzes[version].questions;
|
questions = data.quizzes[version].questions;
|
||||||
|
questions = shuffleArray(questions); // Randomize the order of questions
|
||||||
displayQuestion();
|
displayQuestion();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -63,6 +64,15 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
quizContainer.innerHTML = '<p>Error loading quiz. Please try again later.</p>';
|
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() {
|
function displayQuestion() {
|
||||||
if (!questions || currentQuestionIndex >= questions.length) {
|
if (!questions || currentQuestionIndex >= questions.length) {
|
||||||
showResults();
|
showResults();
|
||||||
@@ -162,6 +172,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
correctAnswer: currentQuestion.answer,
|
correctAnswer: currentQuestion.answer,
|
||||||
isCorrect: isCorrect,
|
isCorrect: isCorrect,
|
||||||
questionIndex: currentQuestionIndex,
|
questionIndex: currentQuestionIndex,
|
||||||
|
ordinalNumber: currentQuestionIndex + 1, // Store the ordinal number of the question
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
timeSpent: 25000 - timeLeft, // Time spent in milliseconds
|
timeSpent: 25000 - timeLeft, // Time spent in milliseconds
|
||||||
chartType: currentQuestion.chart,
|
chartType: currentQuestion.chart,
|
||||||
|
|||||||
Reference in New Issue
Block a user