user962206
user962206

Reputation: 16117

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>

Upvotes: 0

Views: 469

Answers (4)

petrkotek
petrkotek

Reputation: 4761

You are missing "*" between "12.7" and heightInInches":

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

Upvotes: 0

Kanwal Sarwara
Kanwal Sarwara

Reputation: 413

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

You forgot the * in ( 12.7 heightInInches )

Upvotes: 0

slebetman
slebetman

Reputation: 113866

Here's the bug:

12.7 heightInInches

the identifier heightInInches is not expected to be in this location. What is expected is an operator like *, +, - or /

Upvotes: 0

Andrew Whitaker
Andrew Whitaker

Reputation: 126042

Did you mean to multiply?

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

Upvotes: 2

Related Questions