Changed around line 1
+ const words = []; // Will be populated with words from the MIT word list
+ let currentWord = '';
+ let correctCount = 0;
+ let totalCount = 0;
+
+ // DOM Elements
+ const wordInput = document.getElementById('word-input');
+ const playButton = document.getElementById('play-button');
+ const hintButton = document.getElementById('hint-button');
+ const submitButton = document.getElementById('submit-button');
+ const feedbackMessage = document.getElementById('feedback-message');
+ const correctCountElement = document.getElementById('correct-count');
+ const totalCountElement = document.getElementById('total-count');
+ const accuracyElement = document.getElementById('accuracy');
+
+ // Load words from MIT word list
+ fetch('https://www.mit.edu/~ecprice/wordlist.10000')
+ .then(response => response.text())
+ .then(data => {
+ words.push(...data.split('\n').filter(word => word.length > 3 && word.length < 8));
+ newWord();
+ });
+
+ // Audio functions
+ function playWord() {
+ const utterance = new SpeechSynthesisUtterance(currentWord);
+ utterance.rate = 0.8;
+ speechSynthesis.speak(utterance);
+ }
+
+ // Game logic
+ function newWord() {
+ currentWord = words[Math.floor(Math.random() * words.length)];
+ wordInput.value = '';
+ feedbackMessage.textContent = '';
+ wordInput.classList.remove('correct', 'incorrect');
+ }
+
+ function checkSpelling() {
+ const userInput = wordInput.value.toLowerCase();
+ totalCount++;
+
+ if (userInput === currentWord) {
+ correctCount++;
+ feedbackMessage.textContent = 'Correct!';
+ wordInput.classList.add('correct');
+ playSuccessSound();
+ } else {
+ feedbackMessage.textContent = 'Try again!';
+ wordInput.classList.add('incorrect');
+ playErrorSound();
+ }
+
+ updateStats();
+ newWord();
+ }
+
+ function showHint() {
+ const userInput = wordInput.value.toLowerCase();
+ let hint = '';
+
+ for (let i = 0; i < currentWord.length; i++) {
+ if (userInput[i] === currentWord[i]) {
+ hint += currentWord[i];
+ } else {
+ hint += '_';
+ }
+ }
+
+ wordInput.value = hint;
+ }
+
+ function updateStats() {
+ correctCountElement.textContent = correctCount;
+ totalCountElement.textContent = totalCount;
+ const accuracy = totalCount ? Math.round((correctCount / totalCount) * 100) : 0;
+ accuracyElement.textContent = `${accuracy}%`;
+ }
+
+ // Audio feedback
+ function playSuccessSound() {
+ const audio = new Audio('data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=');
+ audio.play();
+ }
+
+ function playErrorSound() {
+ const audio = new Audio('data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=');
+ audio.play();
+ }
+
+ // Event listeners
+ playButton.addEventListener('click', playWord);
+ hintButton.addEventListener('click', showHint);
+ submitButton.addEventListener('click', checkSpelling);
+ wordInput.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ checkSpelling();
+ }
+ });
+
+ // Initialize
+ newWord();