-
[DHTML] Unlimited Timer
1) CODE TITLE: Unlimited Timer
2) AUTHOR NAME/NOTES: Michael Burt (http://mburt.funpic.org)
3) DESCRIPTION: This timer script allows you to have as many terms as you want, ex: 5:40:23:14. Or even 0:14, which would be fourteen seconds, it will count down to 0:00.
4) URL TO CODE/DEMO: http://mburt.funpic.org/testing/countdown.htm
-
What would 15:14:13:12:11:10:9:8:7:6:5:4:3:2:1 be? One second, two minutes, three hours, four days, five weeks, six months, seven years, eight decades, nine centuries, ten millennia? Then what?
-
Hmm... It's possibilities are endless, "15:14:13:12:11:10:9:8:7:6:5:4:3:2:1" would still be valid :p. I'm not sure what's after ten millenia though.
-
You've mutilated my Number.prototype.pad() function :p It can be written much more neatly as:
Code:
Number.prototype.pad = function(n) {
for(var r = this.toString(); r.length < n; r = 0 + r);
return r;
};
Also, you should avoid using innerHTML, and you should object-orient the script in case someone wants more than one on the page.
Other than that, however, very good -- I understand how it works now (I'd only glanced at it before) :) It's a variation on the base-26 problem I saw here recently.
-
I tried using that function, but it didn't work... At all. I think It was trying to read it as a string or something.
After spending two hours coding it, I was way too lazy to replace innerHTML with:
Code:
while (el.firstChild) el.removeChild(el.firstChild);
el.appendChild(document.createTextNode(x.substring(0,x.length-1)+fext;))
Whoa... I just did. :p
-
Oops. There's a syntax error... Stupid semi-colens.
-
Hmn, works here. I was doing r = r + 0 instead of r = 0 + r in the one above (edited now) but I'm fairly sure I don't usually make that mistake.
-
Actually, before you had r = "0" + r as a string.
-
No matter, it's type-coerced into a string anyway.
-
Right... I forgot the whole .toString() bit.