Changed around line 1
+ const wordList = [];
+ let currentWord = '';
+ let correctCount = 0;
+ let totalCount = 0;
+
+ // Fetch word list
+ fetch('https://www.mit.edu/~ecprice/wordlist.10000')
+ .then(response => response.text())
+ .then(text => {
+ wordList.push(...text.split('\n'));
+ getNewWord();
+ });
+
+ // Audio context setup
+ const audioContext = new (window.AudioContext || window.webkitAudioContext)();
+
+ // Elements
+ const playBtn = document.getElementById('playBtn');
+ const enterBtn = document.getElementById('enterBtn');
+ const hintBtn = document.getElementById('hintBtn');
+ const wordInput = document.getElementById('wordInput');
+ const correctCountEl = document.getElementById('correctCount');
+ const totalCountEl = document.getElementById('totalCount');
+ const successRateEl = document.getElementById('successRate');
+
+ // Speech synthesis setup
+ const synth = window.speechSynthesis;
+
+ function getNewWord() {
+ currentWord = wordList[Math.floor(Math.random() * wordList.length)];
+ }
+
+ function playWord() {
+ const utterance = new SpeechSynthesisUtterance(currentWord);
+ synth.speak(utterance);
+ }
+
+ function playSound(frequency, type = 'success') {
+ const oscillator = audioContext.createOscillator();
+ const gainNode = audioContext.createGain();
+
+ oscillator.connect(gainNode);
+ gainNode.connect(audioContext.destination);
+
+ oscillator.type = 'sine';
+ oscillator.frequency.setValueAtTime(frequency, audioContext.currentTime);
+
+ gainNode.gain.setValueAtTime(0.1, audioContext.currentTime);
+
+ oscillator.start();
+ oscillator.stop(audioContext.currentTime + 0.2);
+ }
+
+ function checkWord() {
+ totalCount++;
+ totalCountEl.textContent = totalCount;
+
+ if (wordInput.value.toLowerCase() === currentWord.toLowerCase()) {
+ correctCount++;
+ correctCountEl.textContent = correctCount;
+ playSound(800);
+ getNewWord();
+ wordInput.value = '';
+ } else {
+ playSound(200, 'error');
+ }
+
+ successRateEl.textContent = `${Math.round((correctCount/totalCount) * 100)}%`;
+ }
+
+ function showHint() {
+ const input = wordInput.value.toLowerCase();
+ const correct = currentWord.toLowerCase();
+ let hintText = '';
+
+ for(let i = 0; i < input.length; i++) {
+ if(input[i] === correct[i]) {
+ hintText += input[i];
+ } else {
+ hintText += '❌';
+ }
+ }
+
+ wordInput.value = hintText;
+ }
+
+ // Event Listeners
+ playBtn.addEventListener('click', playWord);
+ enterBtn.addEventListener('click', checkWord);
+ hintBtn.addEventListener('click', showHint);
+ wordInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') checkWord();
+ });
+
+ // Virtual Keyboard
+ document.querySelectorAll('.keyboard-row button').forEach(button => {
+ button.addEventListener('click', () => {
+ wordInput.value += button.textContent;
+ wordInput.focus();
+ });
+ });