0

I am taking my first JavaScript class. The first two exercises I did worked great. This one however is not. Nothing all all shows up in the browser. It is just a white page. Any suggestions would be greatly appreciated.

<!DOCTYPE html PUBLIC "_//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <script type="text/javascript">
      var degFahren = Number(prompt("Enter the degrees Fahrenheit",32));
      var degCent; 
      degCent = 5/9 * (degFahren - 32));
      document.write(degFahren + "\xB0 Fahrenheit is " + degCent + "\xB0 centigrade<br />";
      if (degCet < 0) { document.write("That's below the freezing point of water");}
      if (degCent == 100) { document.write("That's the boiling point of water"); }
    </script>
   </body>
</html>
2
  • 1
    You have a typo; degCet > degCent in your first if statement. Commented Jul 7, 2014 at 20:08
  • Thanks...that is what was not letting my if statements work. Commented Jul 7, 2014 at 20:18

1 Answer 1

6

This code should work. These are easy to spot problems, just open up your javascript console (F12) and you'll see you have an extra ) on line 8, and a missing one line 10. There was also a typo on degCent.

<!DOCTYPE html PUBLIC "_//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<script type="text/javascript">
    var degFahren = Number(prompt("Enter the degrees Fahrenheit",32));
    var degCent; 
    degCent = 5/9 * (degFahren - 32);
    document.write(degFahren + "\xB0 Fahrenheit is " + degCent + "\xB0 centigrade<br />");
    if (degCent < 0) { document.write("That's below the freezing point of water");}
    if (degCent == 100) { document.write("That's the boiling point of water"); }
 </script>
 </body>
 </html>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Sorry I did not see that.
@floyd Don't be sorry if you did not know about the javascript console, but always use it in the future, it will save you a lot of time ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.