js检测人的身高体重比是否正常

 

函数:检测人的身高体重比是否正常(单位:m 单位:kg)

//检测人的身高体重比是否正常
function testing(height, weight) {
  var bmi = weight / (height * height);
  if (bmi <= 0) {
    console.log('不能是负数');
  } else {
    if (bmi <= 18.5) {
      console.log('过轻');
    } else {
      if (bmi <= 25) {
        console.log('正常');
      } else {
        if (bmi <= 28) {
          console.log('过重');
        } else {
          if (bmi <= 32) {
            console.log('过于肥胖');
          } else {
            console.log('请填正确填写身高体重');
          }
        }
      }
    }
  }
}

 

使用:

testing(1.7, 75);

结果:

 

posted @ 2021-06-28 15:22  herry菌  阅读(202)  评论(0编辑  收藏  举报