I'm struggling to incorporate leading zeros into the minutes and seconds of this javascript countdown timer. I can't seem to make the leadingzero function work properly. The additional leadingzero function that I added doesn't appear to be functioning as intended:
<pre><html>
<head>
</head.
<body>
<p style="font-size:100px;">
<div id="countdown"></div> </p>
<div id="notifier"></div>
<script type="text/javascript">
function display( notifier, str ) {
document.getElementById(notifier).innerHTML = str;
}
function toMinuteAndSecond( x ) {
return Math.floor(x/60) + ":" + x%60;
}
function setTimer( remain, actions ) {
(function countdown() {
display("countdown", toMinuteAndSecond(remain));
actions[remain] && actions[remain]();
(remain -= 1) >= 0 && setTimeout(arguments.callee, 1000);
})();
}
function leadingzero(setTimer) {
if (setTimer < 10 && setTimer >=0)
return '0' + setTimer;
else
return setTimer ;
}
setTimer(600, {
10: function () { display("notifier", "Just 10 seconds to go"); },
5: function () { display("notifier", "5 seconds left"); },
0: function () { display("notifier", "Your access is no longer guaranteed.. you need to refresh your page to gain another spot"); }
});
</script>
</body>
</html>
</pre>