Skip to content

Instantly share code, notes, and snippets.

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 VanessaPellegrini/d94df671e13d36dec1198f6e15202401 to your computer and use it in GitHub Desktop.
Save VanessaPellegrini/d94df671e13d36dec1198f6e15202401 to your computer and use it in GitHub Desktop.
Calculate BMI
//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