Enter a word that starts with the last letter of the previous word:
Enter a word that starts with the last letter of the previous word:
\n \nTime is up! You lose!
';\n document.getElementById('inputWord').disabled = true;\n }\n }, 1000);\n}\n\nfunction handleKeyPress(event) {\n if (event.key === 'Enter') {\n playGame();\n }\n}\n\nfunction playGame() {\n const inputWord = document.getElementById('inputWord').value.toLowerCase();\n const outputDiv = document.getElementById('output');\n\n if (inputWord === '') {\n outputDiv.innerHTML = 'Please enter a word.
';\n return;\n }\n\n if (!wordList.includes(inputWord)) {\n outputDiv.innerHTML = `\"${inputWord}\" is not in the word list. You lose!
`;\n clearInterval(timer);\n document.getElementById('inputWord').disabled = true;\n return;\n }\n\n if (usedWords.has(inputWord)) {\n outputDiv.innerHTML = `\"${inputWord}\" has already been used. You lose!
`;\n clearInterval(timer);\n document.getElementById('inputWord').disabled = true;\n return;\n }\n\n if (lastLetter !== '' && inputWord[0] !== lastLetter) {\n outputDiv.innerHTML = `\"${inputWord}\" does not start with \"${lastLetter}\". You lose!
`;\n clearInterval(timer);\n document.getElementById('inputWord').disabled = true;\n return;\n }\n\n usedWords.add(inputWord);\n lastLetter = inputWord[inputWord.length - 1];\n\n outputDiv.innerHTML = `You entered: ${inputWord}
`;\n\n const computerWord = findComputerWord(lastLetter);\n\n if (computerWord === null) {\n outputDiv.innerHTML += 'Computer cannot find a word. You win!
';\n clearInterval(timer);\n document.getElementById('inputWord').disabled = true;\n return;\n }\n\n usedWords.add(computerWord);\n lastLetter = computerWord[computerWord.length - 1];\n\n outputDiv.innerHTML += `Computer responds with: ${computerWord}
`;\n\n document.getElementById('inputWord').value = '';\n startTimer();\n}\n\nfunction findComputerWord(startLetter) {\n const availableWords = wordList.filter(word => \n word[0] === startLetter && !usedWords.has(word)\n );\n\n if (availableWords.length === 0) {\n return null;\n }\n\n return availableWords[Math.floor(Math.random() * availableWords.length)];\n}\n\nstartTimer();\n---end---"Enter a word that starts with the last letter of the previous word:
Time is up! You lose!
';Please enter a word.
';"${inputWord}" is not in the word list. You lose!
`;"${inputWord}" has already been used. You lose!
`;"${inputWord}" does not start with "${lastLetter}". You lose!
`;You entered: ${inputWord}
`;Computer cannot find a word. You win!
';Computer responds with: ${computerWord}
`;