How To Calculate BMI Calculator With JavaScript?

BMI (Body Mass Index) means the ratio of a person’s weight (kg) and the square of that person’s height (m). BMI calculates the value of a person’s health in some different ranges.

Formula:

BMI = (weight) / (height * height)

The ideal value of BMI is 18.5 to 24.9. Anyone having a BMI within this range is healthy enough to lead a better life.

The Chart Is given below.

A BMI calculator is a tool that helps to find out BMI easily. By using a BMI calculator, one does not need to calculate manually. He can just put his weight in kilograms and height in meters and click the button “Calculate”/or something of the same task. The calculator will give him his BMI result and as well as comment on his health condition.

If you want to design the BMI calculator using HTML, CSS & JS please try to follow the below source code.

HTML:

 

 

BMI Calculator

 

 

CSS:





 

JS:

function calculateBmi() {
var weight = document.techBMI.weight.value
var height = document.techBMI.height.value

if( weight > 0 && height > 0 ) {
var finalBmi = weight/(height*height)
document.techBMI.bmi.value = finalBmi.toFixed(3);

if( finalBmi < 18.5 ) { document.techBMI.meaning.value = “You are unhealthy, too thin.” } if( finalBmi > 18.5 && finalBmi < 25 ) { document.techBMI.meaning.value = “You are healthy enough.” } if( finalBmi > 25 && finalBmi <30 ) { document.techBMI.meaning.value = “You have overweight.” } if( finalBmi > 30 ) {
document.techBMI.meaning.value = “Your condition is serious.”
}
}
else {
alert(“Data you’ve entered might be incorrect. Please check and try again.”)
}
}

That’s it.

Thanks & enjoy happy coding.

Leave a Reply

Your email address will not be published. Required fields are marked *