Changed around line 1
+ const words = [
+ "accommodate", "bureaucracy", "conscientious", "dilemma",
+ "embarrass", "fluorescent", "handkerchief", "liaison",
+ "maneuver", "necessary", "occurrence", "pneumonia",
+ "questionnaire", "rhythm", "separate", "threshold"
+ ];
+
+ let currentWord = "";
+ 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 correctCountSpan = document.getElementById("correct-count");
+ const attemptedCountSpan = document.getElementById("attempted-count");
+ const accuracySpan = document.getElementById("accuracy");
+
+ function getRandomWord() {
+ if (usedWords.length === words.length) {
+ usedWords = [];
+ }
+
+ let word = words[Math.floor(Math.random() * words.length)];
+ while (usedWords.includes(word)) {
+ word = words[Math.floor(Math.random() * words.length)];
+ }
+ usedWords.push(word);
+ return word;
+ }
+
+ function speakWord(word) {
+ const utterance = new SpeechSynthesisUtterance(word);
+ utterance.rate = 0.8;
+ speechSynthesis.speak(utterance);
+ }
+
+ function updateStats() {
+ const accuracy = attemptedCount === 0 ? 0 : Math.round((correctCount / attemptedCount) * 100);
+ correctCountSpan.textContent = correctCount;
+ attemptedCountSpan.textContent = attemptedCount;
+ accuracySpan.textContent = `${accuracy}%`;
+ }
+
+ function checkSpelling() {
+ const userInput = wordInput.value.toLowerCase();
+ if (userInput === currentWord) {
+ correctCount++;
+ attemptedCount++;
+ wordInput.value = "";
+ alert("Correct! 🎉");
+ speakWord("Correct");
+ updateStats();
+ newWord();
+ } else {
+ attemptedCount++;
+ wordInput.value = "";
+ alert("Incorrect, try again!");
+ speakWord("Incorrect");
+ updateStats();
+ speakWord(currentWord);
+ }
+ }
+
+ function newWord() {
+ currentWord = getRandomWord();
+ speakWord(currentWord);
+ }
+
+ function highlightIncorrectLetters() {
+ const userInput = wordInput.value.toLowerCase();
+ let highlightedWord = "";
+ for (let i = 0; i < currentWord.length; i++) {
+ if (userInput[i] === currentWord[i]) {
+ highlightedWord += userInput[i];
+ } else {
+ highlightedWord += `${userInput[i] || "_"}`;
+ }
+ }
+ wordInput.innerHTML = highlightedWord;
+ }
+
+ playButton.addEventListener("click", newWord);
+ enterButton.addEventListener("click", checkSpelling);
+ hintButton.addEventListener("click", highlightIncorrectLetters);
+
+ document.addEventListener("keydown", (e) => {
+ if (e.key === "Enter") {
+ checkSpelling();
+ } else if (e.key === "Backspace") {
+ wordInput.value = wordInput.value.slice(0, -1);
+ } else if (/^[a-zA-Z]$/.test(e.key)) {
+ wordInput.value += e.key.toLowerCase();
+ }
+ });
+
+ // Initialize first word
+ newWord();