Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: [DHTML] Unlimited Timer

  1. #1
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default [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
    - Mike

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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 . I'm not sure what's after ten millenia though.
    - Mike

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You've mutilated my Number.prototype.pad() function 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.
    Last edited by Twey; 04-06-2007 at 09:45 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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.
    - Mike

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Oops. There's a syntax error... Stupid semi-colens.
    - Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Actually, before you had r = "0" + r as a string.
    - Mike

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No matter, it's type-coerced into a string anyway.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Right... I forgot the whole .toString() bit.
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •