# 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.

## Script For BMI Calculator

```<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>BMI Calculator</title>
<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>
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

5 1 vote
Article Rating
Subscribe
Notify of

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