I want to stop a timeup counter at the same moment when the game ends. (bomb explodes, all the bombs are found).
The end of my Javascript is here:
//timeup counter
let minutesLabel = document.getElementById("minutes");
let secondsLabel = document.getElementById("seconds");
let totalSeconds = 0;
setInterval(setTime, 1000);
function setTime() {
++totalSeconds;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
}
function pad(val) {
var valString = val + "";
if (valString.length < 2) {
return "0" + valString;
} else {
return valString;
}
}
//game over
function gameOver(square) {
result.innerHTML = 'BOOM! Game Over!'
isGameOver = true
}
//show ALL the bombs
squares.forEach(square => {
if (square.classList.contains('bomb')) {
square.innerHTML = '