Results 1 to 7 of 7

Thread: test this little site please (converts temperature units)

  1. #1
    Join Date
    Apr 2007
    Beans
    14,781

    test this little site please (converts temperature units)

    http://laroza.freehostia.com/home/calculator/

    It is written in client side ECMAScript, and I tried to make it useable, let me know what you think.

    IE6 handle it weird, visually, but otherwise works. FF, Opera, Safari, and IE7 handle it fine.

    Feedback appreciated.

    Thanks.
    Last edited by LaRoza; September 21st, 2007 at 02:13 PM.

  2. #2
    Join Date
    Aug 2007
    Location
    NY, United States
    Beans
    169
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: test this little site please (converts temperature units)

    I can type 123-45 in there, and it will accept (and convert) the first part of the number.

    Maybe you want to evaluate the input box with a regex that goes something like this:

    /$[0-9](.[0-9])?^/

    Or however it goes. I'm not exactly sharp with Regular Expressions.

    Though if you go down this path, maybe you also want to ignore whitespace:

    /$[ ]*[0-9](.[0-9])?[ ]*^/

    ...And trim it out when you run the conversion.
    Last edited by aaaantoine; September 21st, 2007 at 04:04 PM. Reason: Missing )

  3. #3
    Join Date
    Apr 2007
    Beans
    14,781

    Re: test this little site please (converts temperature units)

    Quote Originally Posted by aaaantoine View Post
    I can type 123-45 in there, and it will accept (and convert) the first part of the number.
    I didn't want to make it too restrictive, validation can be a difficult thing to do right, but the general rule is to not be too restrictive.

    Right now, it looks for numbers at the beginning of the input, and uses those (parseFloat). It also round answers to the nearist integer, which I might change to increase precision.

    Thanks, I will look into re for validation, and trimming whitespace is a good idea.

    (I wrote this last night, out of boredom and because I often wish to put temps on this forum, but don't want to alienate anyone, so use C and F.)

  4. #4
    Join Date
    Apr 2006
    Location
    in the dark
    Beans
    1,513

    Re: test this little site please (converts temperature units)

    try putting in
    8 )
    and converting to and from centigrade. You should make it check each character.
    Imagination is more important than knowledge

  5. #5
    Join Date
    Apr 2007
    Beans
    14,781

    Re: test this little site please (converts temperature units)

    Quote Originally Posted by slimdog360 View Post
    try putting in and converting to and from centigrade. You should make it check each character.
    Overvalidation is not a good thing.

    Putting in non-numerical characters will not give warnings or errors if there are leading numbers.

    The main thing for me was not to have "NaN" show up in the conversion field. I can make it throw errors if any character is invalid, but what if someone copies a temp from a website, like 20 ° C, and puts it in? It will convert it because of the leading 20
    Last edited by LaRoza; September 21st, 2007 at 04:57 PM.

  6. #6
    Join Date
    Jul 2007
    Location
    The Internet
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: test this little site please (converts temperature units)

    It worked once for me, then stopped working (just toggles between F & C).

    Also, when I hit refresh, a bright red message about JavaScript not working flashes momentarily then disappears (though my javascript is on & is fine)...

  7. #7
    Join Date
    Feb 2007
    Location
    Montreal, Canada
    Beans
    191

    Re: test this little site please (converts temperature units)

    I can only do one conversion. After, the bouton are sheded and become useless. The need to refresh would probably be considered an annoyance.

    Negative number and 0 don't work. If you don't know what -20 °C feels like I really envy you.

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
  •