Changed around line 1
+ const wordList = [
+ 'accommodate', 'bureaucracy', 'conscientious', 'dilemma',
+ 'embarrass', 'fluorescent', 'handkerchief', 'liaison',
+ 'maneuver', 'millennium', 'occasionally', 'pneumonia',
+ 'questionnaire', 'rhythm', 'separate', 'supersede',
+ 'threshold', 'unnecessary', 'vacuum', 'withhold'
+ ];
+
+ let currentWord = '';
+ let userInput = '';
+ let correctCount = 0;
+ let attemptedCount = 0;
+ let usedWords = [];
+
+ 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 correctCountDisplay = document.getElementById('correct-count');
+ const attemptedCountDisplay = document.getElementById('attempted-count');
+ const accuracyPercentDisplay = document.getElementById('accuracy-percent');
+
+ function getRandomWord() {
+ const availableWords = wordList.filter(word => !usedWords.includes(word));
+ if (availableWords.length === 0) {
+ alert('Congratulations! You\'ve completed all words!');
+ return;
+ }
+ const randomIndex = Math.floor(Math.random() * availableWords.length);
+ currentWord = availableWords[randomIndex];
+ usedWords.push(currentWord);
+ }
+
+ function playWord() {
+ const utterance = new SpeechSynthesisUtterance(currentWord);
+ speechSynthesis.speak(utterance);
+ }
+
+ function updateStats() {
+ const accuracy = attemptedCount === 0 ? 0 : Math.round((correctCount / attemptedCount) * 100);
+ correctCountDisplay.textContent = correctCount;
+ attemptedCountDisplay.textContent = attemptedCount;
+ accuracyPercentDisplay.textContent = `${accuracy}%`;
+ }
+
+ function handleKeyPress(key) {
+ if (key === 'Backspace') {
+ userInput = userInput.slice(0, -1);
+ } else if (key === 'Enter') {
+ checkSpelling();
+ } else if (/^[a-zA-Z]$/.test(key)) {
+ userInput += key.toLowerCase();
+ }
+ wordInput.value = userInput;
+ }
+
+ function checkSpelling() {
+ attemptedCount++;
+ if (userInput === currentWord) {
+ correctCount++;
+ playSound('correct');
+ getRandomWord();
+ userInput = '';
+ wordInput.value = '';
+ updateStats();
+ } else {
+ playSound('incorrect');
+ alert(`Incorrect! Try again.`);
+ playWord();
+ }
+ updateStats();
+ }
+
+ function playSound(type) {
+ const audio = new Audio();
+ audio.src = type === 'correct' ? 'correct.mp3' : 'incorrect.mp3';
+ audio.play();
+ }
+
+ function highlightIncorrectLetters() {
+ const inputLetters = userInput.split('');
+ const wordLetters = currentWord.split('');
+ let highlightedWord = '';
+
+ wordLetters.forEach((letter, index) => {
+ if (inputLetters[index] === letter) {
+ highlightedWord += letter;
+ } else {
+ highlightedWord += `${letter}`;
+ }
+ });
+
+ wordInput.innerHTML = highlightedWord;
+ }
+
+ // Initialize
+ getRandomWord();
+
+ // Event Listeners
+ document.querySelectorAll('.key').forEach(button => {
+ button.addEventListener('click', () => {
+ const key = button.textContent === '←' ? 'Backspace' : button.textContent;
+ handleKeyPress(key);
+ });
+ });
+
+ playButton.addEventListener('click', playWord);
+ enterButton.addEventListener('click', checkSpelling);
+ hintButton.addEventListener('click', highlightIncorrectLetters);
+
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Backspace' || e.key === 'Enter' || /^[a-zA-Z]$/.test(e.key)) {
+ handleKeyPress(e.key);
+ }
+ });