diff --git a/gun-imperiyasy.html b/gun-imperiyasy.html index fc3a1a1..2a6e5ba 100644 --- a/gun-imperiyasy.html +++ b/gun-imperiyasy.html @@ -185,6 +185,16 @@ let timerInterval = null; let seconds = 0; let userName = ''; let answered = false; +let shuffledQuestions = []; + +function shuffleArray(array) { + const shuffled = [...array]; + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; + } + return shuffled; +} function checkLogin() { const savedName = localStorage.getItem('ebtUserName'); @@ -253,13 +263,14 @@ function startQuiz() { currentQuestion = 0; answers = {}; seconds = 0; + shuffledQuestions = shuffleArray(QUESTIONS); startTimer(); - document.getElementById('q-total').textContent = QUESTIONS.length; + document.getElementById('q-total').textContent = shuffledQuestions.length; showQuestion(); } function showQuestion() { - const q = QUESTIONS[currentQuestion]; + const q = shuffledQuestions[currentQuestion]; document.getElementById('q-current').textContent = currentQuestion + 1; document.getElementById('question-text').textContent = q.q; @@ -347,7 +358,7 @@ function showResults() { let correct = 0; let wrong = 0; - QUESTIONS.forEach((q, i) => { + shuffledQuestions.forEach((q, i) => { if (answers[i] === q.correct) { correct++; } else { @@ -355,7 +366,7 @@ function showResults() { } }); - const percentage = Math.round((correct / QUESTIONS.length) * 100); + const percentage = Math.round((correct / shuffledQuestions.length) * 100); document.getElementById('quiz-section').classList.add('hidden'); document.getElementById('result-section').classList.remove('hidden'); diff --git a/index.html b/index.html index 4b6ecad..b7637b7 100644 --- a/index.html +++ b/index.html @@ -176,6 +176,16 @@ let timerInterval = null; let seconds = 0; let userName = ''; let answered = false; +let shuffledQuestions = []; + +function shuffleArray(array) { + const shuffled = [...array]; + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; + } + return shuffled; +} function checkLogin() { const savedName = localStorage.getItem('ebtUserName'); @@ -244,13 +254,14 @@ function startQuiz() { currentQuestion = 0; answers = {}; seconds = 0; + shuffledQuestions = shuffleArray(QUESTIONS); startTimer(); - document.getElementById('q-total').textContent = QUESTIONS.length; + document.getElementById('q-total').textContent = shuffledQuestions.length; showQuestion(); } function showQuestion() { - const q = QUESTIONS[currentQuestion]; + const q = shuffledQuestions[currentQuestion]; document.getElementById('q-current').textContent = currentQuestion + 1; document.getElementById('question-text').textContent = q.q; @@ -338,15 +349,16 @@ function showResults() { let correct = 0; let wrong = 0; - QUESTIONS.forEach((q, i) => { - if (answers[i] === q.correct) { + shuffledQuestions.forEach((q, i) => { + const originalIndex = QUESTIONS.findIndex(orig => orig.q === q.q); + if (answers[i] === originalIndex) { correct++; } else { wrong++; } }); - const percentage = Math.round((correct / QUESTIONS.length) * 100); + const percentage = Math.round((correct / shuffledQuestions.length) * 100); document.getElementById('quiz-section').classList.add('hidden'); document.getElementById('result-section').classList.remove('hidden'); diff --git a/qanly-uysin-sarmattar.html b/qanly-uysin-sarmattar.html index c13ac36..699b8a3 100644 --- a/qanly-uysin-sarmattar.html +++ b/qanly-uysin-sarmattar.html @@ -179,6 +179,16 @@ let timerInterval = null; let seconds = 0; let userName = ''; let answered = false; +let shuffledQuestions = []; + +function shuffleArray(array) { + const shuffled = [...array]; + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; + } + return shuffled; +} function checkLogin() { const savedName = localStorage.getItem('ebtUserName'); @@ -247,13 +257,14 @@ function startQuiz() { currentQuestion = 0; answers = {}; seconds = 0; + shuffledQuestions = shuffleArray(QUESTIONS); startTimer(); - document.getElementById('q-total').textContent = QUESTIONS.length; + document.getElementById('q-total').textContent = shuffledQuestions.length; showQuestion(); } function showQuestion() { - const q = QUESTIONS[currentQuestion]; + const q = shuffledQuestions[currentQuestion]; document.getElementById('q-current').textContent = currentQuestion + 1; document.getElementById('question-text').textContent = q.q; @@ -341,7 +352,7 @@ function showResults() { let correct = 0; let wrong = 0; - QUESTIONS.forEach((q, i) => { + shuffledQuestions.forEach((q, i) => { if (answers[i] === q.correct) { correct++; } else { @@ -349,7 +360,7 @@ function showResults() { } }); - const percentage = Math.round((correct / QUESTIONS.length) * 100); + const percentage = Math.round((correct / shuffledQuestions.length) * 100); document.getElementById('quiz-section').classList.add('hidden'); document.getElementById('result-section').classList.remove('hidden');