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 playButton = document.getElementById('play-button');
+ 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 totalCountDisplay = document.getElementById('total-count');
+ const accuracyPercentDisplay = document.getElementById('accuracy-percent');
+
+ 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)];
+ wordInput.value = '';
+ feedbackMessage.textContent = '';
+ wordInput.classList.remove('correct', 'incorrect');
+ }
+
+ function playWord() {
+ const utterance = new SpeechSynthesisUtterance(currentWord);
+ utterance.lang = 'en-US';
+ speechSynthesis.speak(utterance);
+ }
+
+ function checkSpelling() {
+ const userInput = wordInput.value.toLowerCase();
+ totalCount++;
+ totalCountDisplay.textContent = totalCount;
+
+ if (userInput === currentWord) {
+ correctCount++;
+ correctCountDisplay.textContent = correctCount;
+ feedbackMessage.textContent = 'Correct! Great job!';
+ wordInput.classList.add('correct');
+ playSound('correct');
+ } else {
+ feedbackMessage.textContent = 'Incorrect. Try again!';
+ wordInput.classList.add('incorrect');
+ playSound('incorrect');
+ playWord();
+ }
+
+ updateAccuracy();
+ newWord();
+ }
+
+ function updateAccuracy() {
+ const accuracy = (correctCount / totalCount) * 100;
+ accuracyPercentDisplay.textContent = accuracy.toFixed(1);
+ }
+
+ function showHint() {
+ const userInput = wordInput.value.toLowerCase();
+ let hint = '';
+ for (let i = 0; i < currentWord.length; i++) {
+ if (userInput[i] === currentWord[i]) {
+ hint += userInput[i];
+ } else {
+ hint += `${userInput[i] || '_'}`;
+ }
+ }
+ wordInput.innerHTML = hint;
+ }
+
+ function playSound(type) {
+ const audio = new Audio();
+ audio.src = type === 'correct' ? 'correct.mp3' : 'incorrect.mp3';
+ audio.play();
+ }
+
+ document.addEventListener('DOMContentLoaded', fetchWords);
+ playButton.addEventListener('click', playWord);
+ enterButton.addEventListener('click', checkSpelling);
+ hintButton.addEventListener('click', showHint);
+
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ checkSpelling();
+ }
+ });
+
+ // Virtual keyboard functionality
+ document.querySelectorAll('.keyboard button').forEach(button => {
+ if (!['Play', 'Enter', 'Hint'].includes(button.textContent)) {
+ button.addEventListener('click', () => {
+ wordInput.value += button.textContent.toLowerCase();
+ });
+ }
+ });