// /public/js/quiz/study.js let questions = []; // Fetch all questions and render them async function initStudyMode() { const loadingState = document.getElementById('loading-state'); const questionsContainer = document.getElementById('questions-container'); const errorState = document.getElementById('error-state'); const totalDisplay = document.getElementById('total-questions'); try { // Fetch ALL questions (use mode=all to get the full dataset) const response = await fetch('/api/quiz/questions?mode=all'); if (!response.ok) { throw new Error('Failed to fetch questions'); } questions = await response.json(); loadingState.style.display = 'none'; if (questions.length > 0) { totalDisplay.textContent = `${questions.length} Questions Total`; questionsContainer.style.display = 'block'; renderAllQuestions(); } else { throw new Error('No questions received'); } } catch (error) { console.error(error); loadingState.style.display = 'none'; errorState.style.display = 'block'; } } // Render all questions with their correct answers highlighted function renderAllQuestions() { const container = document.getElementById('questions-container'); container.innerHTML = ''; questions.forEach((q, index) => { // Find the correct answer const correctAnswer = q.answers.find(a => a.is_correct); // Create question card const card = document.createElement('div'); card.className = 'question-card'; card.style.marginBottom = '2rem'; card.innerHTML = `