2012-10-27 106 views
0

對於這行代碼被識別爲一個的Javascript意外意外標識符

一些奇怪的原因此特定線是

`Unexpected identifier` 

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

這是整個代碼

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); 
    } 

} 

這是整個標記

<!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> 
+0

檢查您的代碼的哪一列出現異常 – Bergi

回答

2

你的意思是繁殖嗎?

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

等等,沒有看到錯誤,我不會在上網本中再次編碼。 – user962206

0

這裏的錯誤:

12.7 heightInInches 

標識符heightInInches預計不會在這個位置。什麼是預期的是運營商,如*,+, - 或/

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

您在(12.7 heightInInches)

0

忘了*你缺少 「*」, 「12.7」 之間heightInInches「:

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