// array of words to be displayed randomly const words = [ 'red', 'car', 'bed', 'hat', 'cat', 'mat', 'pet', 'bin', 'run', 'bun', 'the', 'and', 'of', 'in', 'is', 'but', 'it', 'bat', 'bar', 'map', 'sap', 'cap', 'hen', 'ten', 'jar', 'tip', 'lip', 'fin', 'was', 'good' ]; // initial player score let score = 0; // variable to grab a random word from the array const randomWord = words[Math.floor(Math.random() * words.length)]; // function for replacing the word displayed function replaceWord() { console.log('new word'); document.querySelector('h1').innerHTML = `${words[Math.floor(Math.random() * words.length)]}`; } // this function increases score variable by one, changes the score displayed, and prints it to the console function increaseScore() { score += 1; document.querySelector('.player-score').innerHTML = `${score}`; console.log(`score increased to ${score}`) } // click event for the green correct button, increases the score and replaces the displayed word document.querySelector('.correct').addEventListener("click", () => { increaseScore(); replaceWord(); }); // click event for the red wrong button, replaces the word displayed with a new one document.querySelector('.wrong').addEventListener("click", () => { replaceWord(); });