控制台错误含义

Console error meaning?

本文关键字:错误 控制台      更新时间:2023-09-26

我是编程新手,无法弄清楚我正在处理的这段代码出了什么问题。在开发人员控制台中,我不断收到这些错误代码。

Hw%20multifuncion.html:24 未捕获SyntaxError:意外令牌非法 Hw multifuncion.html :34 未捕获ReferenceError:未定义计算

这是什么意思?我还不熟悉调试器,所以任何帮助将不胜感激。

<!DOCTYPE HTML>
<html lang="en-us">
<head>
  <meta charset="utf-8">
  <title>WindChill</title>
  <script type="text/javascript">
    /* Input: Temperature in fahrenheit and windspeed in mph
     * Processing: Calculate windchill and output to user. While useing two funcions, and assign a call and return.
     * Output: The windchill
     */
    function compute() {
      var temperature = document.getElementById("temperature").value;
      var windspeed = document.getElementById("windspeed").value;
      var temp = parseInt(temperature);
      var wind = parseInt(windspeed);
      var result = windChill(temp, wind);
      document.getElementById("output").innerHTML = result;
    }
    function windChill(tempF, speed) {
      var f = 35.74 + 0.6215 * tempF− 35.75 * Math.pow(speed, 0.16) + 0.4275 * Math.pow(tempF, 0.16);
    }
  </script>
</head>
<body>
  Temperature (Fahrenheit)
  <input type="text" id="temperature" size="5">
  <br>Wind speed (MPH)
  <input type="text" id="windspeed" size="5">
  <button type="button" onclick="compute()">WindChill</button>
  <div id="output"></div>
</body>
</html>

问题出在您的windChill函数中:您使用的是而不是-符号。

function windChill(tempF,speed) {
    var f = 35.74 + 0.6215*tempF - 35.75*Math.pow(speed,0.16) + 0.4275*Math.pow (tempF,0.16);
}

您的windChill函数有两个问题:

  • 它需要返回一个结果。就像现在一样,您将计算分配给f,但您不对它执行任何操作。

  • 正如Darshan指出的那样,你的减号-符号似乎不正确。

只需在变量赋值后添加return f;并更正减号即可。