最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

counter - How to end Countup Timer - Javascript - Stack Overflow

programmeradmin0浏览0评论

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 = '
发布评论

评论列表(0)

  1. 暂无评论