Created
January 24, 2021 03:47
-
-
Save VanessaPellegrini/d94df671e13d36dec1198f6e15202401 to your computer and use it in GitHub Desktop.
Calculate BMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Write function bmi that calculates body mass index (bmi = weight / height ^ 2). | |
//if bmi <= 18.5 return "Underweight" | |
//if bmi <= 25.0 return "Normal" | |
//if bmi <= 30.0 return "Overweight" | |
//if bmi > 30 return "Obese" | |
function bmi(weight, height) { | |
//pow permite elevar un exponente | |
let bmi = weight/Math.pow(height,2); | |
//formatea un número usando notación de punto fijo. | |
bmi = Number(bmi.toFixed(1)) | |
console.log(bmi) | |
if(bmi <= 18.5){ | |
return 'Underweight'; | |
} | |
if(bmi <= 25.5){ | |
return 'Normal' | |
} | |
if(bmi <= 30){ | |
return 'Overweight' | |
} | |
if(bmi > 30){ | |
return 'Obese' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment