Before we go too much further with our cupcakes, let’s edit the endGame
function we created earlier so that instead of publishing a message to the console, it changes the value stored in our timeUp
variable to true.
function endGame() {
- console.log('Game has finished');
+ timeUp = true;
}
We’ll also need to make sure we set timeUp
back to false when the game starts again.
function startGame() {
+ timeUp = false;
popUp();
setTimeout(endGame, 10000);
}
This is what you should have in CodePen so far:
let timeUp = false;
let holes = document.querySelectorAll('.hole');
let scoreBoard = document.querySelector('.score');
function startGame() {
timeUp = false;
popUp();
setTimeout(endGame, 10000);
}
function endGame() {
timeUp = true;
}
function popUp() {
let hole = holes[0];
hole.classList.add('up');
}