// π Game state let allWords = [], words = [], current = 0, results = []; // π©βπ Show student interface function showStudent() { console.log("π showStudent() executed"); const studentPanel = document.getElementById('studentPanel'); const adminPanel = document.getElementById('adminPanel'); studentPanel?.classList.remove('hidden'); adminPanel?.classList.add('hidden'); setTimeout(() => { const btn = document.getElementById('startGameBtn'); if (btn) { console.log("π― Button found in delayed reveal"); btn.classList.remove('hidden'); btn.style.display = 'inline-block'; } else { console.warn("β οΈ Button still missing after timeout"); } }, 100); } // π Begin game session async function startGame() { const user = JSON.parse(localStorage.getItem('loggedInUser')); if (!user) return; const res = await fetch(`/getWordList?user=${encodeURIComponent(user.username)}`); allWords = await res.json(); if (!allWords.length) { alert("No words found. Please add words in Admin Panel."); return; } words = [...allWords]; current = 0; results = []; document.getElementById('summary')?.classList.add('hidden'); document.getElementById('badgeDisplay')?.classList.add('hidden'); showWord(); } // π€ Show a word, then hide after timeout function showWord() { const wordBox = document.getElementById('wordBox'); const wordEl = document.getElementById('word'); if (!words[current]) { endGame(); return; } wordEl.textContent = words[current]; wordBox.classList.remove('hidden'); setTimeout(() => { wordBox.classList.add('hidden'); document.getElementById('inputSection').classList.remove('hidden'); document.getElementById('userInput').value = ''; document.getElementById('userInput').focus(); }, 2000); } // π Check userβs answer and move to next function submitAnswer() { const input = document.getElementById('userInput').value.trim(); results.push({ word: words[current], attempt: input }); current++; document.getElementById('inputSection').classList.add('hidden'); if (current < words.length) { showWord(); } else { showSummary(); } } // π Show results summary function showSummary() { const summary = document.getElementById('summary'); let correct = 0; let missed = []; const report = results.map(({ word, attempt }) => { const isCorrect = word.toLowerCase() === attempt.toLowerCase(); if (isCorrect) correct++; else missed.push(word); return `
You got ${correct} out of ${words.length} correct (${Math.round((correct / words.length) * 100)}%)