Skip to content

Instantly share code, notes, and snippets.

@Wanuja97
Created February 23, 2021 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wanuja97/e2a7293dc535152e48d1093d5e321139 to your computer and use it in GitHub Desktop.
Save Wanuja97/e2a7293dc535152e48d1093d5e321139 to your computer and use it in GitHub Desktop.
BMI Calculator - JavaScript Part
function Calculate(){
var height = document.getElementById("h-input").value;
var weight = document.getElementById("w-input").value;
var result = parseFloat(weight) /(parseFloat(height)/100)**2;
if(!isNaN(result)){
document.getElementById("bmi-output").innerHTML = result;
if(result < 18.5){
document.getElementById("bmi-status").innerHTML = "Underweight";
}
else if(result < 25){
document.getElementById("bmi-status").innerHTML = "Healthy";
}
else if(result < 30){
document.getElementById("bmi-status").innerHTML = "Overweight";
}
else{
document.getElementById("bmi-status").innerHTML = "Obesity";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment