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

4
Leave a Reply

avatar
3 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
kishanSanjay PrasadAisha khan Recent comment authors

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

  Subscribe  
newest oldest most voted
Notify of
Aisha khan
Guest
Aisha khan

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

Aisha khan
Guest
Aisha khan

Tell me plz

kishan
Guest
kishan

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

Do you have any Query / Suggestion