Changed around line 1
+ const words = [
+ 'accommodation', 'bureaucracy', 'conscientious', 'desiccate',
+ 'entrepreneur', 'fluorescent', 'gymnasium', 'hierarchy',
+ 'immediate', 'jurisdiction', 'kaleidoscope', 'lieutenant',
+ 'maintenance', 'necessary', 'occurrence', 'parliament',
+ 'questionnaire', 'resistance', 'surveillance', 'thoroughly'
+ ];
+
+ let currentWord = '';
+ let correctCount = 0;
+ let totalCount = 0;
+
+ const wordDisplay = document.getElementById('word-display');
+ const playBtn = document.getElementById('play-btn');
+ const enterBtn = document.getElementById('enter-btn');
+ const hintBtn = document.getElementById('hint-btn');
+ const correctCounter = document.getElementById('correct-count');
+ const totalCounter = document.getElementById('total-count');
+ const successRate = document.getElementById('success-rate');
+
+ // Speech synthesis setup
+ const speak = (text) => {
+ const utterance = new SpeechSynthesisUtterance(text);
+ speechSynthesis.speak(utterance);
+ };
+
+ // Sound effects
+ const createBeep = (frequency, duration) => {
+ const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
+ const oscillator = audioCtx.createOscillator();
+ const gainNode = audioCtx.createGain();
+
+ oscillator.connect(gainNode);
+ gainNode.connect(audioCtx.destination);
+
+ oscillator.frequency.value = frequency;
+ oscillator.start();
+
+ setTimeout(() => {
+ oscillator.stop();
+ }, duration);
+ };
+
+ const playCorrectSound = () => createBeep(1000, 200);
+ const playIncorrectSound = () => createBeep(200, 500);
+
+ // Get random word
+ const getRandomWord = () => {
+ return words[Math.floor(Math.random() * words.length)];
+ };
+
+ // Initialize game
+ const initGame = () => {
+ currentWord = getRandomWord();
+ wordDisplay.textContent = '_'.repeat(currentWord.length);
+ };
+
+ // Handle key input
+ const handleKeyInput = (key) => {
+ const currentDisplay = wordDisplay.textContent;
+ if (currentDisplay === '_'.repeat(currentWord.length)) {
+ wordDisplay.textContent = key;
+ } else {
+ wordDisplay.textContent += key;
+ }
+ };
+
+ // Keyboard event listeners
+ document.addEventListener('keydown', (e) => {
+ if (e.key === 'Enter') {
+ enterBtn.click();
+ } else if (/^[a-zA-Z]$/.test(e.key)) {
+ handleKeyInput(e.key.toLowerCase());
+ }
+ });
+
+ // Virtual keyboard setup
+ document.querySelectorAll('.keyboard-row button').forEach(button => {
+ button.addEventListener('click', () => {
+ handleKeyInput(button.textContent.toLowerCase());
+ });
+ });
+
+ // Button event listeners
+ playBtn.addEventListener('click', () => {
+ speak(currentWord);
+ });
+
+ enterBtn.addEventListener('click', () => {
+ totalCount++;
+ if (wordDisplay.textContent.toLowerCase() === currentWord) {
+ correctCount++;
+ playCorrectSound();
+ alert('Correct!');
+ } else {
+ playIncorrectSound();
+ alert('Incorrect! Try again.');
+ speak(currentWord);
+ }
+
+ correctCounter.textContent = correctCount;
+ totalCounter.textContent = totalCount;
+ successRate.textContent = `${Math.round((correctCount/totalCount) * 100)}%`;
+
+ initGame();
+ });
+
+ hintBtn.addEventListener('click', () => {
+ const current = wordDisplay.textContent.toLowerCase();
+ let hinted = '';
+ for (let i = 0; i < current.length; i++) {
+ if (current[i] !== currentWord[i]) {
+ hinted += `${current[i]}`;
+ } else {
+ hinted += current[i];
+ }
+ }
+ wordDisplay.innerHTML = hinted;
+ });
+
+ // Initialize the game
+ initGame();