Temp Conversion Program...Help please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nyy

    Temp Conversion Program...Help please

    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>Temperat ure 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] = i;
    }
    for (var j=0, j<100, ++j) {
    celcius = (fahrenheit[i] - 32) * .55
    document.write( fahrenheit[i] + " degrees Fahrenheit is equal to "
    + celcius + celsius.<br />);
    }
    // STOP HIDING FROM INCOMPATIBLE BROWSERS -->
    </script>
    </head>
    <body>
    </body>
    </html>

  • pipe

    #2
    Re: Temp Conversion Program...Help please


    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.c om/kyoosho/

    Comment

    • RobG

      #3
      Re: Temp Conversion Program...Help please

      nyy wrote:[color=blue]
      > 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>Temperat ure Conversion</title>
      > <script type="text/javascript">
      > <!-- HIDE FROM INCOMPATIBLE BROWSERS[/color]

      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...
      [color=blue]
      > var fahrenheit = new Array();[/color]

      This array is not required.
      [color=blue]
      > var celcius = 0;[/color]

      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

      Comment

      • Robi

        #4
        Re: Temp Conversion Program...Help please

        nyy wrote in message news:1127315157 .354396.84050@f 14g2000cwb.goog legroups.com...[color=blue]
        > 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.[/color]

        Hi nyy, this is King Sapingo, remember me ;-)

        I have a few comments:
        [color=blue]
        > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/color]

        why XHTML
        [color=blue]
        > <html>
        > <head>
        > <title>Temperat ure Conversion</title>
        > <script type="text/javascript">
        > <!-- HIDE FROM INCOMPATIBLE BROWSERS[/color]
        ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^
        as someone else mentioned in another post,
        there are no /incompatible browsers/
        (in other words, you don't need this,
        unless you actually publish it as XML (XHTML)
        then you need the <![CDATA[ definition)

        anyway, back to your problem:
        [color=blue]
        > var fahrenheit = new Array();
        > var celcius = 0;
        > for (var i = 0; i <= 100; ++i) {
        > fahrenheit[i] = i;
        > }
        > for (var j=0, j<100, ++j) {[/color]
        ^ ^
        for (init ; while;incr)
        you also probably mean j<=100
        since you said i<=100 earlier

        for (var j=0; j<=100; ++j)
        [color=blue]
        > celcius = (fahrenheit[i] - 32) * .55[/color]
        ^ ^
        didn't you want j instead of i? and end the line with ";"
        (you will be surprised about some of the results "* 0.55" yelds ;-)
        [color=blue]
        > document.write( fahrenheit[i] + " degrees Fahrenheit is equal to "[/color]
        ^
        the same j instead of i?
        [color=blue]
        > + celcius + celsius.<br />);[/color]
        ^^^^^^^^^^^^^^^
        you probably want this in "quotes"[color=blue]
        > }
        > // STOP HIDING FROM INCOMPATIBLE BROWSERS -->
        > </script>
        > </head>
        > <body>
        > </body>
        > </html>[/color]

        HTH

        Comment

        • Dr John Stockton

          #5
          Re: Temp Conversion Program...Help please

          JRS: In article <1127315157.354 396.84050@f14g2 000cwb.googlegr oups.com>,
          dated Wed, 21 Sep 2005 08:05:57, seen in news:comp.lang. javascript, nyy
          <jet800@yahoo.c om> posted :
          [color=blue]
          > celcius = (fahrenheit[i] - 32) * .55[/color]

          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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          Working...