Changed around line 1
+ const wordListUrl = 'https://www.mit.edu/~ecprice/wordlist.10000';
+ let words = [];
+ let currentWord = '';
+ let correctCount = 0;
+ let totalCount = 0;
+
+ const wordToSpell = document.getElementById('word-to-spell');
+ 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 feedbackText = document.getElementById('feedback-text');
+ 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);
+ getNewWord();
+ }
+
+ function getNewWord() {
+ currentWord = words[Math.floor(Math.random() * words.length)];
+ wordToSpell.textContent = currentWord;
+ wordInput.value = '';
+ feedbackText.textContent = '';
+ }
+
+ function playWord() {
+ const utterance = new SpeechSynthesisUtterance(currentWord);
+ speechSynthesis.speak(utterance);
+ }
+
+ function checkSpelling() {
+ const userInput = wordInput.value.trim().toLowerCase();
+ totalCount++;
+ totalCountDisplay.textContent = totalCount;
+
+ if (userInput === currentWord.toLowerCase()) {
+ correctCount++;
+ correctCountDisplay.textContent = correctCount;
+ feedbackText.textContent = 'Correct!';
+ feedbackText.style.color = 'var(--success-color)';
+ playSuccessSound();
+ } else {
+ feedbackText.textContent = 'Incorrect. Try again!';
+ feedbackText.style.color = 'var(--error-color)';
+ playErrorSound();
+ }
+
+ updateAccuracy();
+ getNewWord();
+ }
+
+ function updateAccuracy() {
+ const accuracy = (correctCount / totalCount) * 100;
+ accuracyPercentDisplay.textContent = `${accuracy.toFixed(1)}%`;
+ }
+
+ function playSuccessSound() {
+ const audio = new Audio('success.mp3');
+ audio.play();
+ }
+
+ function playErrorSound() {
+ const audio = new Audio('error.mp3');
+ audio.play();
+ }
+
+ function highlightIncorrectLetters() {
+ const userInput = wordInput.value.trim().toLowerCase();
+ const correctWord = currentWord.toLowerCase();
+ let highlightedWord = '';
+
+ for (let i = 0; i < correctWord.length; i++) {
+ if (userInput[i] === correctWord[i]) {
+ highlightedWord += `${correctWord[i]}`;
+ } else {
+ highlightedWord += `${correctWord[i]}`;
+ }
+ }
+
+ wordToSpell.innerHTML = highlightedWord;
+ }
+
+ playButton.addEventListener('click', playWord);
+ enterButton.addEventListener('click', checkSpelling);
+ hintButton.addEventListener('click', highlightIncorrectLetters);
+ wordInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') {
+ checkSpelling();
+ }
+ });
+
+ fetchWords();