Calculate BMI

Lee·2022년 8월 8일

Algorithm

목록 보기
67/92
post-thumbnail

❓ Calculate BMI

Q. Write function bmi that calculates body mass index (bmi = weight / height2).

if bmi <= 18.5 return "Underweight"

if bmi <= 25.0 return "Normal"

if bmi <= 30.0 return "Overweight"

if bmi > 30 return "Obese"

✔ Solution

//#my solution
function bmi(weight, height) {
  let bw = weight;
  let bh = Math.pow(height, 2);
  let result = bw / bh;
  if (result <= 18.5) {
    return "Underweight";
  } else if (result <= 25.0) {
    return "Normal";
  } else if (result <= 30.0) {
    return "Overweight";
  } else {
    return "Obese";
  }
}

//#other solution
function bmi(weight, height) {
  var result = weight/Math.pow(height,2) 
  
  if (result <= 18.5) {
    return "Underweight";
  } else if (result <= 25) {
    return "Normal";
  } else if (result <= 30) {
    return "Overweight";
  } else {
    return "Obese";
  }
  
}
profile
Lee

0개의 댓글