简体   繁体   English

JavaScript内联代码未显示在浏览器中

[英]JavaScript inline code not showing up in browser

I am taking my first JavaScript class. 我正在上我的第一堂JavaScript课。 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>

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 . 这些很容易发现问题,只需打开JavaScript控制台 (F12) ,您就会在第8行看到一个额外的) ,而在第10行缺少了一个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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM