Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Can anyone help me find the error/s in this script?

    Code:
    <!DOCTYPE html>
    <html>
    <head>
        <title>Fahrenheit From Celsius</title>
    </head>
    <body>
        <script>
            var cTemp = 100;  // temperature in Celsius
            // Let's be generous with parentheses
            var hTemp = ((cTemp * 9) /5 ) + 32;
            document.write("Temperature in Celsius: " + cTemp + "
    degrees<br/>");
            document.write("Temperature in Fahrenheit: " + hTemp + "
    degrees");
        </script>
    </body>
    </html>
    Thanks

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    Have you tried using your error console?

    The errors are in the line breaks in your document.write() statements.

    var hTemp = cTemp * 9/5 + 32; // is entirely adequate.


    This is the country [North Korea] where most people go hungry due to lack of food. - Commentator Radio 4

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    turtleflame (12-28-2012)

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    When I eliminated the line breaks it didn't change anything but when I removed all of the parentheses it did work. Thank you.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,316
    Thanks
    203
    Thanked 2,566 Times in 2,544 Posts
    Quote Originally Posted by turtleflame View Post
    When I eliminated the line breaks it didn't change anything but when I removed all of the parentheses it did work. Thank you.
    Not so. The line breaks are your problem - easily demonstrated.

    Code:
    var cTemp = 100;  // temperature in Celsius
    // Let's be generous with parentheses
    var hTemp = ((cTemp * 9) /5 ) + 32;
    alert (hTemp); // 212

    BTW, do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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