add function for replacing word when clicking the correct button

This commit is contained in:
2025-08-28 11:04:44 -04:00
parent d857789455
commit e3c377d547

View File

@@ -15,6 +15,15 @@ const words = [
// 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;
@@ -22,9 +31,8 @@ function increaseScore() {
console.log(`score increased to ${score}`)
}
// this is the click event that runs the increaseScore function
// click event for the green correct button, increases the score and replaces the displayed word
document.querySelector('.correct').addEventListener("click", () => {
increaseScore();
increaseScore();
replaceWord();
});
console.log( words[2] );