From e3c377d547a016c6680543c76d9b87e6a70033c2 Mon Sep 17 00:00:00 2001 From: Mike Rockwell Date: Thu, 28 Aug 2025 11:04:44 -0400 Subject: [PATCH] add function for replacing word when clicking the correct button --- wally/app.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wally/app.js b/wally/app.js index 599730b..28e9d38 100644 --- a/wally/app.js +++ b/wally/app.js @@ -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(); -}); - -console.log( words[2] ); \ No newline at end of file + increaseScore(); + replaceWord(); +}); \ No newline at end of file