add function for replacing word when clicking the correct button
This commit is contained in:
16
wally/app.js
16
wally/app.js
@@ -15,6 +15,15 @@ const words = [
|
|||||||
// initial player score
|
// initial player score
|
||||||
let score = 0;
|
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
|
// this function increases score variable by one, changes the score displayed, and prints it to the console
|
||||||
function increaseScore() {
|
function increaseScore() {
|
||||||
score += 1;
|
score += 1;
|
||||||
@@ -22,9 +31,8 @@ function increaseScore() {
|
|||||||
console.log(`score increased to ${score}`)
|
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", () => {
|
document.querySelector('.correct').addEventListener("click", () => {
|
||||||
increaseScore();
|
increaseScore();
|
||||||
|
replaceWord();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log( words[2] );
|
|
Reference in New Issue
Block a user