2025-08-28 10:16:31 -04:00
|
|
|
// array of words to be displayed randomly
|
2025-08-27 12:09:24 -04:00
|
|
|
const words = [
|
|
|
|
'red',
|
|
|
|
'car',
|
2025-08-28 10:06:38 -04:00
|
|
|
'bed',
|
|
|
|
'hat',
|
|
|
|
'cat',
|
|
|
|
'mat',
|
|
|
|
'pet',
|
|
|
|
'bin',
|
|
|
|
'run',
|
|
|
|
'bun'
|
2025-08-27 12:09:24 -04:00
|
|
|
];
|
|
|
|
|
2025-08-28 10:16:31 -04:00
|
|
|
// initial player score
|
|
|
|
let score = 0;
|
|
|
|
|
2025-08-28 11:04:44 -04:00
|
|
|
// 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)]}`;
|
|
|
|
}
|
|
|
|
|
2025-08-28 10:16:31 -04:00
|
|
|
// 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}`)
|
|
|
|
}
|
|
|
|
|
2025-08-28 11:04:44 -04:00
|
|
|
// click event for the green correct button, increases the score and replaces the displayed word
|
2025-08-28 10:16:31 -04:00
|
|
|
document.querySelector('.correct').addEventListener("click", () => {
|
2025-08-28 11:04:44 -04:00
|
|
|
increaseScore();
|
|
|
|
replaceWord();
|
|
|
|
});
|