Changed around line 1
+ const wordListUrl = 'https://www.mit.edu/~ecprice/wordlist.10000';
+ let words = [];
+ let currentWord = '';
+ let correctCount = 0;
+ let attemptedCount = 0;
+
+ const wordAudio = document.getElementById('word-audio');
+ const playButton = document.getElementById('play-button');
+ const wordInput = document.getElementById('word-input');
+ const enterButton = document.getElementById('enter-button');
+ const hintButton = document.getElementById('hint-button');
+ const feedbackMessage = document.getElementById('feedback-message');
+ const correctCountDisplay = document.getElementById('correct-count');
+ const attemptedCountDisplay = document.getElementById('attempted-count');
+ const successRateDisplay = document.getElementById('success-rate');
+
+ async function fetchWords() {
+ const response = await fetch(wordListUrl);
+ const text = await response.text();
+ words = text.split('\n').filter(word => word.length > 3 && word.length < 8);
+ loadNewWord();
+ }
+
+ function loadNewWord() {
+ currentWord = words[Math.floor(Math.random() * words.length)];
+ wordAudio.src = `https://ssl.gstatic.com/dictionary/static/sounds/oxford/${currentWord}--_gb_1.mp3`;
+ wordInput.value = '';
+ feedbackMessage.textContent = '';
+ words = words.filter(word => word !== currentWord);
+ }
+
+ function checkSpelling() {
+ const userInput = wordInput.value.trim().toLowerCase();
+ attemptedCount++;
+ if (userInput === currentWord) {
+ feedbackMessage.textContent = 'Correct!';
+ feedbackMessage.style.color = 'green';
+ correctCount++;
+ new Audio('correct.mp3').play();
+ } else {
+ feedbackMessage.textContent = 'Incorrect, try again.';
+ feedbackMessage.style.color = 'red';
+ new Audio('incorrect.mp3').play();
+ }
+ updateStats();
+ loadNewWord();
+ }
+
+ function updateStats() {
+ correctCountDisplay.textContent = correctCount;
+ attemptedCountDisplay.textContent = attemptedCount;
+ const successRate = ((correctCount / attemptedCount) * 100).toFixed(2);
+ successRateDisplay.textContent = `${successRate}%`;
+ }
+
+ function highlightIncorrectLetters() {
+ const userInput = wordInput.value.trim().toLowerCase();
+ let highlightedWord = '';
+ for (let i = 0; i < currentWord.length; i++) {
+ if (userInput[i] !== currentWord[i]) {
+ highlightedWord += `${userInput[i] || '_'}`;
+ } else {
+ highlightedWord += userInput[i] || '_';
+ }
+ }
+ wordInput.innerHTML = highlightedWord;
+ }
+
+ playButton.addEventListener('click', () => wordAudio.play());
+ enterButton.addEventListener('click', checkSpelling);
+ hintButton.addEventListener('click', highlightIncorrectLetters);
+ wordInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') checkSpelling();
+ });
+
+ fetchWords();