Temp Conversion Program...Help please

Discussion in 'Javascript' started by nyy, Sep 21, 2005.

  1. nyy

    nyy Guest

    Hello everybody on this group. I have this program that is supposed to
    display a temp. conversion from fahrenheit to celsius, can anybody
    kindly can tell me what is wrong? Thanks.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Temperature Conversion</title>
    <script type="text/javascript">
    <!-- HIDE FROM INCOMPATIBLE BROWSERS
    var fahrenheit = new Array();
    var celcius = 0;
    for (var i = 0; i <= 100; ++i) {
    fahrenheit = i;
    }
    for (var j=0, j<100, ++j) {
    celcius = (fahrenheit - 32) * .55
    document.write(fahrenheit + " degrees Fahrenheit is equal to "
    + celcius + celsius.<br />);
    }
    // STOP HIDING FROM INCOMPATIBLE BROWSERS -->
    </script>
    </head>
    <body>
    </body>
    </html>
     
    nyy, Sep 21, 2005
    #1
    1. Advertising

  2. nyy

    pipe Guest

    for (var i = 0; i <= 100; ++i) {

    for (var j=0, j<100, ++j) {

    notice the <= in the first line and the < in the second.

    notice also that u dont need the array.

    and also that you are using document.write in the head section, and not
    in the body section.



    --
    [php/javascript/coldfusion/ajax stuff]
    http://www.geocities.com/kyoosho/
     
    pipe, Sep 21, 2005
    #2
    1. Advertising

  3. nyy

    RobG Guest

    nyy wrote:
    > Hello everybody on this group. I have this program that is supposed to
    > display a temp. conversion from fahrenheit to celsius, can anybody
    > kindly can tell me what is wrong? Thanks.
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    > <html>
    > <head>
    > <title>Temperature Conversion</title>
    > <script type="text/javascript">
    > <!-- HIDE FROM INCOMPATIBLE BROWSERS


    Forget using HTML comments inside script elements, particularly if your
    browser is interpreting this as genuine XHTML - in which case
    document.write may cause you some heartache too.

    But never mind...

    > var fahrenheit = new Array();


    This array is not required.

    > var celcius = 0;


    This variable is not needed. If the intention is to write conversions
    for 0 to 100 degrees Celsius to Fahrenheit, then the following:

    for (var i=0; i <= 100; ++i) {
    document.write( i + ' degrees Celcius is equal to '
    + (Math.round(i*9/5 + 32))
    + ' degrees Fahrenheit.<br />'
    );
    }

    should do the trick, unless the point of the exercise was to use an array?

    [...]




    --
    Rob
     
    RobG, Sep 21, 2005
    #3
  4. JRS: In article <>,
    dated Wed, 21 Sep 2005 08:05:57, seen in news:comp.lang.javascript, nyy
    <> posted :

    > celcius = (fahrenheit - 32) * .55


    Your ".55" should be written "0.55". Javascript will understand either,
    bur relying on a half-bare decimal dot is liable to lead to human error.
    See, if you have access, IUPAP-25 / SUNAMCO 87-1.

    The conversion factor is in fact not 0.55 but bigger.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Sep 22, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    596
    Big Brian
    Oct 14, 2003
  2. Replies:
    2
    Views:
    576
    Mark P
    May 9, 2005
  3. arnuld
    Replies:
    11
    Views:
    586
    arnuld
    Mar 6, 2007
  4. A. Farber
    Replies:
    3
    Views:
    264
    Ben Morrow
    Mar 3, 2004
  5. PerlFAQ Server
    Replies:
    0
    Views:
    262
    PerlFAQ Server
    Apr 26, 2011
Loading...

Share This Page