

Use the same like document.getElementById("comment").innerHTML = "Underweight" You cannot use like document.getElementById("comment").value = "Underweight" If (BMI = 18.5 & BMI = 25 & BMI 30) document.getElementById("comment").innerHTML = "Overweight" And i don't understand what you wish to accomplish by the statement document.getElementById("answer").value = output so unless you explain that, i have commented it.ĭocument.getElementById("output").innerHTML = Math.round(BMI * 100)/100 and document.getElementById("comment") results in an empty set(null), hence the error : Cannot set property value of null. With the help of the index you can understand whether you are unhealthily thin or conversely. The things wrong with what you have done, is that the var output is not assigned any value. Body mass index is the ratio of your weight to height. document.getElementById("answer").value = output

If (output = 18.5 & output = 25 & output 30)ĭocument.getElementById("comment").innerText = "Overweight" Var BMI = Math.round(weight / Math.pow(height, 2) * 10000) ĭocument.getElementById("output").innerText = Math.round(BMI * 100) / 100 var BMI = weight /Math.pow(height, 2)*10000 Var weightunits = document.getElementById("weightunits").value Var weight = Number(document.getElementById("weight").value) Var heightunits = document.getElementById("heightunits").value Var height = Number(document.getElementById("height").value) You will need to enter your height in either centimeters or feet and inches, depending on what units you use. Here are the steps to follow: Enter your height.
#Body mass index calculator with steps how to#
If (output=18.5 & output=25 & output30)ĭocument.getElementById("comment").value = "Overweight" ĭocument.getElementById("answer").value = output How to use our BMI Calculator Using a BMI (body mass index) calculator is a simple and straightforward process. Var weightunits=document.getElementById("weightunits").value Var weight=Number(document.getElementById("weight").value) Var heightunits=document.getElementById("heightunits").value Var height=Number(document.getElementById("height").value) Please can someone help me fix my calculator, I know there are problems with my if statements? Thanks.

There should be a message shown underneath: your bmi is:, and then the message underneath is this means you are: according to the BMI calculated above. I am trying to create a basic HTML/JavaScript BMI calculator.
