Can anyone tell my why this timer:
function timer() {
var counter = 0,
cDisplay = document.getElementById("counter");
format = function(t) {
var hours = Math.floor(t/360000),
minutes = Math.floor( (t/6000) % 60),
seconds = Math.floor( (t/100) % 60),
ms = (Math.floor(t % 100)/100).toFixed(2);
if (t<6000) {
cDisplay.innerHTML = seconds + ms.substring(1);
} else if (t<360000) {
seconds = (seconds < 10) ? "0" + seconds.toString() : seconds.toString();
cDisplay.innerHTML = minutes + ":" + seconds + ms.substring(1);
} else {
minutes = (minutes < 10) ? "0" + minutes.toString() : minutes.toString();
seconds = (seconds < 10) ? "0" + seconds.toString() : seconds.toString();
cDisplay.innerHTML = hours + ":" + minutes + ":" + seconds + ms.substring(1);
}
};
setInterval(function() {
counter++;
format(counter);
},10);
}
won't start when I click on this label:
<label onClick="timer()" id="counter">Start Timer</label>
I can make it load automatically by throwing parentheses around the whole function and slapping a semi-colon on the end like this:
but I can't figure out why it won't load with onClick="timer()". I feel like it's something really obvious that I'm missing but I just can't see it