This timer works successfully, but I’d like to add a 1 second delay before it starts, here’s the code:
“`
var Clock = {
totalSeconds: 0,
start: function () {
if (!this.interval) {
var self = this;
function pad(val) { return val > 9 ? val : “0” + val; }
this.interval = setInterval(function () {
self.totalSeconds += 1;
document.getElementById(“min”).innerHTML = Math.floor(self.totalSeconds / 60 % 60);
document.getElementById(“sec”).innerHTML = pad(parseInt(self.totalSeconds % 60));
}, 1000);
}
},
reset: function () {
Clock.totalSeconds = null;
clearInterval(this.interval);
document.getElementById(“min”).innerHTML = “0”;
document.getElementById(“sec”).innerHTML = “00”;
delete this.interval;
},
stop: function () {
clearInterval(this.interval);
delete this.interval;
}
};
document.getElementById(“start”).addEventListener(“click”, function () { Clock.start(); });
document.getElementById(“stop”).addEventListener(“click”, function () { Clock.stop(); });
I tried adding this code at the bottom, but it only made the min/sec not display at all:
“`
document.getElementById(“start”).addEventListener(“click”, function () {
setTimeout(function () {
Clock.start();
}, 1000
});
Any help is appreciated