2016-03-11 184 views
-1

我是编程新手,无法弄清楚我正在处理的这段代码有什么问题。在开发者控制台中,我一直收到这些错误代码。控制台错误含义?

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>

+0

你有一个'-'而不是'-'符号。请求前使用[JSHint](http://jshint.com/)。 – Xufox

+0

你也需要在函数windChill()中返回f;'' – linktoahref

+1

有时候错误可能是神秘的,在你的情况下,它们不是。语法错误不是减号,并且当脚本出错时,没有'compute()'函数,并且一旦修复,函数需要返回一些东西 – adeneo

回答

0

的问题是在你的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); 
} 
+0

非常感谢,它总是这些小事情,我没有看到我的代码到目前为止混乱了.. – Jman

0

windChill功能有两个问题:

  • 它需要返回结果。现在,您可以将计算分配给f,但您对此无能为力。

  • 正如Darshan指出的,看起来你的减号-符号不是正确的。

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