add function for replacing word when clicking the correct button
This commit is contained in:
18
wally/app.js
18
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] );
|
||||
increaseScore();
|
||||
replaceWord();
|
||||
});
|
Reference in New Issue
Block a user