Changed around line 1
+ const words = [
+ "accommodate", "bureaucracy", "conscientious", "dilemma",
+ "embarrass", "fluorescent", "guarantee", "handkerchief",
+ "independent", "jewelry", "kaleidoscope", "liaison",
+ "maneuver", "necessary", "occurrence", "pneumonia",
+ "questionnaire", "rhythm", "separate", "threshold"
+ ];
+
+ let currentWord = "";
+ let usedWords = [];
+ let correctCount = 0;
+ let attemptedCount = 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 correctCountEl = document.getElementById('correct-count');
+ const attemptedCountEl = document.getElementById('attempted-count');
+ const accuracyPercentEl = document.getElementById('accuracy-percent');
+
+ function getNewWord() {
+ if (usedWords.length === words.length) {
+ alert("Congratulations! You've completed all words!");
+ return;
+ }
+
+ const availableWords = words.filter(word => !usedWords.includes(word));
+ currentWord = availableWords[Math.floor(Math.random() * availableWords.length)];
+ usedWords.push(currentWord);
+ speakWord(currentWord);
+ }
+
+ function speakWord(word) {
+ const utterance = new SpeechSynthesisUtterance(word);
+ utterance.voice = speechSynthesis.getVoices().find(voice =>
+ voice.name.includes('Google US English') ||
+ voice.name.includes('Microsoft David')
+ );
+ speechSynthesis.speak(utterance);
+ }
+
+ function checkSpelling() {
+ const userInput = wordInput.value.toLowerCase();
+ attemptedCount++;
+
+ if (userInput === currentWord) {
+ correctCount++;
+ playSuccessSound();
+ wordInput.value = "";
+ getNewWord();
+ } else {
+ playErrorSound();
+ wordInput.value = "";
+ speakWord(currentWord);
+ }
+
+ updateStats();
+ }
+
+ function updateStats() {
+ correctCountEl.textContent = correctCount;
+ attemptedCountEl.textContent = attemptedCount;
+ const accuracy = attemptedCount > 0 ? Math.round((correctCount / attemptedCount) * 100) : 0;
+ accuracyPercentEl.textContent = `${accuracy}%`;
+ }
+
+ function playSuccessSound() {
+ const audio = new Audio('success.mp3');
+ audio.play();
+ }
+
+ function playErrorSound() {
+ const audio = new Audio('error.mp3');
+ audio.play();
+ }
+
+ function highlightErrors() {
+ const userInput = wordInput.value.toLowerCase();
+ const correctLetters = currentWord.split('');
+ const inputLetters = userInput.split('');
+
+ wordInput.value = inputLetters.map((letter, index) =>
+ letter === correctLetters[index] ? letter : `${letter}`
+ ).join('');
+ }
+
+ // Event Listeners
+ playButton.addEventListener('click', () => {
+ if (!currentWord) getNewWord();
+ else speakWord(currentWord);
+ });
+
+ enterButton.addEventListener('click', checkSpelling);
+
+ hintButton.addEventListener('click', highlightErrors);
+
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') checkSpelling();
+ });
+
+ // Initialize
+ getNewWord();