Changed around line 1
+ const words = ["above", "active", "afraid", "after", "ago", "Alaska", "all", "also", "always", "amazing", "American", "and", "angry", "animal", "ant", "any", "anything", "apple", "April", "aren't", "are not", "arm", "art room", "ask", "at", "ate", "attention", "August", "aunt", "autumn", "baby", "bad", "badminton", "bag", "ball", "bamboo", "banana", "basket", "basketball", "bathroom", "be careful", "beach", "bear", "beautiful", "because", "become", "bed", "bedroom", "beef", "before", "behind", "beside", "best", "better", "between", "big", "bigger", "bike", "bird", "black", "blackboard", "blue", "boat", "boating", "body", "book", "bookstore", "both", "bottle", "bought", "bowl", "box", "boy", "bread", "breakfast", "breath", "bridge", "broken", "brother", "brown", "building", "bunny", "bus", "businessman", "busy", "but", "buy", "by", "cake", "camp", "Canada", "Canadian", "Canberra", "candy", "cap", "car", "carrot", "cartoon", "cat", "cave", "chair", "chase", "cheap", "cheetah", "chicken", "children", "China", "Chinese book", "chocolate", "chopsticks", "Christmas", "cinema", "class", "classroom", "clean", "clean my room", "cleaned", "clever", "climbing", "clock", "clothes", "cloudy", "club", "coach", "coat", "cold", "come on", "comic", "comic book", "computer", "computer room", "contest", "cook", "co"];
+
+ let lastLetter = '';
+
+ document.getElementById('submit-btn').addEventListener('click', function() {
+ const playerInput = document.getElementById('player-input').value.toLowerCase();
+ if (words.includes(playerInput)) {
+ if (lastLetter === '' || playerInput.charAt(0) === lastLetter) {
+ lastLetter = playerInput.charAt(playerInput.length - 1);
+ document.getElementById('game-log').innerHTML += `
Player: ${playerInput}
`;
+ computerTurn();
+ } else {
+ alert(`Your word must start with the letter "${lastLetter}"`);
+ }
+ } else {
+ alert('Word not in list!');
+ }
+ document.getElementById('player-input').value = '';
+ });
+
+ function computerTurn() {
+ const possibleWords = words.filter(word => word.charAt(0) === lastLetter);
+ if (possibleWords.length > 0) {
+ const computerWord = possibleWords[Math.floor(Math.random() * possibleWords.length)];
+ lastLetter = computerWord.charAt(computerWord.length - 1);
+ document.getElementById('game-log').innerHTML += `
Computer: ${computerWord}
`;
+ } else {
+ document.getElementById('game-log').innerHTML += `
Computer cannot find a word. You win!
`;
+ }
+ }