Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

How to make a BMI Calculator using Pure Javascript

How to make a BMI Calculator using Pure Javascript

Today I am going to use pure Javascript  to make a web application called BMI Calculator which measures BMI (Body Mass Index).

BMI :  According to Wikipedia The BMI is an attempt to quantify the amount of tissue mass (muscle, fat, and bone) in an individual, and then categorize that person as underweight, normal weight, overweight, or obese based on that value.

Formula : BMI = W / (H/100 * H/100)

Where W is weight in KG and H stands for Height in Centimeter.

Screen shot of BMI Calculator

Script For BMI Calculator

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BMI Calculator</title>
</head>
<body>
BMI = KG / (H/100 * H/100) <br/><br/>
Height in CM
<input type="text" id="cm" > <br/>
Weight in KG
<input type="text" id="kg" > <br/>
<input type="submit" id="submit" value="Submit"> <br/><br/>
Under Weight = Less than 18.6<br/>
Normal Range = 18.6 and 24.9<br/>
Overweight = Greater than 24.9<br/>
<div id="result"></div>

<script>
document.getElementById("submit").addEventListener("click", bmiCalculator);
function bmiCalculator(){
var cm = parseInt(document.getElementById("cm").value);
var kg = parseFloat(document.getElementById("kg").value);

var bmi;
var newCm= parseFloat(cm/100);

bmi = kg / (newCm * newCm);
bmi = bmi.toFixed(1);
console.log(bmi);

document.getElementById("result").innerHTML = bmi;

}
</script>
</body>
</html>

Demo For BMI Calculator

Height in CM

Weight in KG

Under Weight = Less than 18.6
Normal Range = 18.6 and 24.9
Overweight = Greater than 24.9

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Aisha khan

I can’t get output as u show.I write same code as u write.plz tell me solution

Aisha khan

Tell me plz

kishan

it’s working Aisha Khan. i have tried it.

manish Kumar

Nice work brother that help me a lot