// ๐ Game state let words = []; let currentWord = ''; let currentIndex = 0; let results = []; // ๐ Check user's answer and move to next window.submitAnswer = function() { const input = document.getElementById('userInput').value.trim(); // Record the attempt results.push({ word: currentWord, attempt: input }); if (input.toLowerCase() === currentWord.toLowerCase()) { currentIndex++; document.getElementById('inputSection').classList.add('hidden'); setTimeout(() => showWord(), 500); // Brief pause before next word } else { // Show feedback for incorrect answer const inputEl = document.getElementById('userInput'); inputEl.style.borderColor = 'var(--error)'; inputEl.style.backgroundColor = '#fef2f2'; setTimeout(() => { inputEl.style.borderColor = ''; inputEl.style.backgroundColor = ''; inputEl.focus(); }, 1000); } } // Add Enter key support for game input document.addEventListener('DOMContentLoaded', () => { const gameInput = document.getElementById('userInput'); if (gameInput) { gameInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') { submitAnswer(); } }); } });[]; let currentSentence = ''; function showStudent() { console.log("๐ Showing student panel"); // Hide admin panel document.getElementById('adminPanel')?.classList.add('hidden'); // Show student panel and its components const studentPanel = document.getElementById('studentPanel'); studentPanel?.classList.remove('hidden'); // Get the buttons and explicitly set their properties const gameBtn = document.getElementById('startGameBtn'); const typingBtn = document.getElementById('startTypingBtn'); if (gameBtn && typingBtn) { console.log("Found buttons, making visible"); // Remove all possible hiding classes/styles gameBtn.classList.remove('hidden'); typingBtn.classList.remove('hidden'); // Explicitly set display style gameBtn.style.cssText = 'display: inline-block !important; visibility: visible !important;'; typingBtn.style.cssText = 'display: inline-block !important; visibility: visible !important;'; } else { console.error("Could not find game buttons"); } } // ๐ Begin game session window.startGame = async function() { console.log('๐ฎ Starting spelling game'); const user = JSON.parse(localStorage.getItem('loggedInUser')); if (!user) { alert('Please log in first'); return; } try { // Hide student dashboard and other sections document.getElementById('studentPanel').style.display = 'none'; document.getElementById('typingSection').style.display = 'none'; document.getElementById('bibleSection').style.display = 'none'; // Show game section document.getElementById('gameSection').classList.remove('hidden'); document.getElementById('gameSection').style.display = 'block'; document.getElementById('wordBox').textContent = 'Loading...'; document.getElementById('summary')?.classList.add('hidden'); document.getElementById('badgeDisplay')?.classList.add('hidden'); // Fetch words const response = await fetch(`/getWordList?username=${user.username}`); const data = await response.json(); console.log('Received words:', data); if (!data.words || data.words.length === 0) { alert('No words found for practice'); return; } // Start game words = [...data.words]; typingWords = [...data.words]; // Initialize typing words too currentIndex = 0; results = []; // Reset results array showWord(); } catch (error) { console.error('Error:', error); alert('Failed to load words'); } } function showWord() { if (currentIndex >= words.length) { showSummary(); return; } currentWord = words[currentIndex]; console.log('Current word:', currentWord); // Show word briefly then hide const wordBox = document.getElementById('wordBox'); const inputSection = document.getElementById('inputSection'); wordBox.textContent = currentWord; inputSection.classList.add('hidden'); setTimeout(() => { wordBox.textContent = ''; 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(); // Record the attempt results.push({ word: currentWord, attempt: input }); if (input.toLowerCase() === currentWord.toLowerCase()) { currentIndex++; document.getElementById('inputSection').classList.add('hidden'); showWord(); } else { alert('Try again!'); } } // ๐ 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)}%)