Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2012, 07:18 PM   PM User | #1
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
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
turtleflame is offline   Reply With Quote
Old 12-28-2012, 07:27 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
turtleflame (12-28-2012)
Old 12-28-2012, 07:39 PM   PM User | #3
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
When I eliminated the line breaks it didn't change anything but when I removed all of the parentheses it did work. Thank you.
turtleflame is offline   Reply With Quote
Old 12-29-2012, 09:30 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:52 AM.


Advertisement
Log in to turn off these ads.