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
Weight in KG
Under Weight = Less than 18.6
Normal Range = 18.6 and 24.9
Overweight = Greater than 24.9
I can’t get output as u show.I write same code as u write.plz tell me solution
Its working Aisha, post is updated with screen shot that I tested on 22th May 2019
Tell me plz
it’s working Aisha Khan. i have tried it.
Nice work brother that help me a lot
Thank you Manish