简体   繁体   English

Javascript意外的意外标识符

[英]Javascript unexpected Unexpected identifier

For some odd reason this line of code is being identified as an 由于一些奇怪的原因,这行代码被识别为

This specific line is 这条具体路线是

  `Unexpected identifier` 

    bmr =  66 + ( 6.23 * weightInlbs ) + ( 12.7 heightInInches ) - ( 6.8 * age );

this is the whole code 这是整个代码

function metricComputation() {
    var age = document.getElementById("age");
    var weightInlbs = document.getElementById("weight");
    var heightInInches =  feetToInches(new Number(document.getElementById("heightinFt")) , document.getElementById("heightinIn"));
    var bmr;
    var gender = document.getElementById("gender");


    if(gender === "male"){
         bmr =  66 + ( 6.23 * weightInlbs ) + ( 12.7 heightInInches ) - ( 6.8 * age );
    }

}

And this is the whole markup 这是整个标记

<!DOCTYPE>
<html>
    <head>
        <script src="bmrcalc.js"></script>
    </head>
        <body>
            <center>
                    <h1>Basal Metabolic Rate</h1>
                Height: <input type = "text" id ="heightinFt"> ft  <input type = "text" id = "heightinIn"> in <br>
                Weight: <input type = "text" id ="weight">lbs<br>
                Age: <input type = "text" id = "age"><br>
                Gender:<select id = "gender">
                    <option value = "male">Male</option>
                    <option value = "female">Female</option>
                <select> <br>
                <button onclick = "metricComputation()">Compute</button>
                <div id = "result"></div>
            </center>
        </body>
</html>

Did you mean to multiply? 你的意思是成倍增加吗?

bmr =  66 + ( 6.23 * weightInlbs ) + ( 12.7 * heightInInches ) - ( 6.8 * age );
// -----------------------------------------/\

Here's the bug: 这是错误:

12.7 heightInInches

the identifier heightInInches is not expected to be in this location. 标识符heightInInches不应位于此位置。 What is expected is an operator like *, +, - or / 期待的是像*,+, - 或/的运营商

if(gender === "male"){
     bmr =  66 + ( 6.23 * weightInlbs ) + ( 12.7 * heightInInches ) - ( 6.8 * age );
}

You forgot the * in ( 12.7 heightInInches ) 你忘了* in ( 12.7 heightInInches )

您在“12.7”和“heightInInches”之间缺少“*”:

bmr =  66 + ( 6.23 * weightInlbs ) + ( 12.7 * heightInInches ) - ( 6.8 * age );

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

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