Changed around line 1
+ const wordListUrl = 'https://www.mit.edu/~ecprice/wordlist.10000';
+ let words = [];
+ let currentWord = '';
+ let correctCount = 0;
+ let totalCount = 0;
+
+ const wordInput = document.getElementById('word-input');
+ const correctCountSpan = document.getElementById('correct-count');
+ const totalCountSpan = document.getElementById('total-count');
+ const successRateSpan = document.getElementById('success-rate');
+ const message = document.getElementById('message');
+
+ 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);
+ newWord();
+ }
+
+ function newWord() {
+ currentWord = words[Math.floor(Math.random() * words.length)];
+ words = words.filter(word => word !== currentWord);
+ wordInput.value = '';
+ message.textContent = '';
+ }
+
+ function playWord() {
+ const utterance = new SpeechSynthesisUtterance(currentWord);
+ speechSynthesis.speak(utterance);
+ }
+
+ function typeLetter(letter) {
+ wordInput.value += letter.toLowerCase();
+ }
+
+ function deleteLetter() {
+ wordInput.value = wordInput.value.slice(0, -1);
+ }
+
+ function checkWord() {
+ const userWord = wordInput.value.toLowerCase();
+ totalCount++;
+ totalCountSpan.textContent = totalCount;
+
+ if (userWord === currentWord) {
+ correctCount++;
+ correctCountSpan.textContent = correctCount;
+ successRateSpan.textContent = `${Math.round((correctCount / totalCount) * 100)}%`;
+ message.textContent = 'Correct! Great job!';
+ playSound('correct');
+ newWord();
+ } else {
+ message.textContent = 'Incorrect. Try again!';
+ playSound('incorrect');
+ }
+ }
+
+ function showHint() {
+ const userWord = wordInput.value.toLowerCase();
+ let hint = '';
+ for (let i = 0; i < currentWord.length; i++) {
+ if (userWord[i] === currentWord[i]) {
+ hint += currentWord[i];
+ } else {
+ hint += '_';
+ }
+ }
+ wordInput.value = hint;
+ }
+
+ function playSound(type) {
+ const audio = new Audio();
+ audio.src = type === 'correct' ? 'correct.mp3' : 'incorrect.mp3';
+ audio.play();
+ }
+
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ checkWord();
+ } else if (e.key === 'Backspace') {
+ deleteLetter();
+ } else if (/^[a-zA-Z]$/.test(e.key)) {
+ typeLetter(e.key);
+ }
+ });
+
+ fetchWords();