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">
<meta charset="UTF-8">
<title>BMI Calculator</title>
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>

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);

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


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 Comment

Leave a Reply

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

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

Do you have any Query / Suggestion