Javascript教程代码不起作用

时间:2016-03-13 16:18:25

标签: javascript

完成一个Javascript教程并得到了这个应该在屏幕上写一些温度转换的例子。这是教程中的代码,它根本不起作用。屏幕上没有任何内容。   如果有错误,我找不到任何错误。

<!DOCTYPE html>
<html lang="en">

  <head>
    <title>Chapter 3, Example 4</title>
  </head>

  <body>
    <script>
      var degFahren = [212, 32, -459.15];
      var degCent = [];
      var loopCounter;
      for (loopCounter = 0; loopCounter <= 2; loopCounter++) {
        degCent[loopCounter] = 5 / 9 * (degFahren[loopCounter] - 32);
      }
      for (loopCounter = 2; loopCounter >= 0; loopCounter−−) {
        document.write("Value " + loopCounter +
          " was " + degFahren[loopCounter] +
          " degrees Fahrenheit");
        document.write(" which is " + degCent[loopCounter] +
          " degrees centigrade<br />");
      }

    </script>
  </body>

</html>

1 个答案:

答案 0 :(得分:2)

试试这个(只需将更改为-):

<!DOCTYPE html>
<html lang="en">

  <head>
    <title>Chapter 3, Example 4</title>
  </head>

  <body>
    <script>
      var degFahren = [212, 32, -459.15];
      var degCent = [];
      var loopCounter;
      for (loopCounter = 0; loopCounter <= 2; loopCounter++) {
        degCent[loopCounter] = 5 / 9 * (degFahren[loopCounter] - 32);
      }
      for (loopCounter = 2; loopCounter >= 0; loopCounter--) {
        document.write("Value " + loopCounter +
          " was " + degFahren[loopCounter] +
          " degrees Fahrenheit");
        document.write(" which is " + degCent[loopCounter] +
          " degrees centigrade<br />");
      }

    </script>
  </body>

</html>