代码中有一个小错误,应该是 weight/(heightheight),而不是 weight/height2。因为身高的单位是米,需要平方才能得到正确的BMI值。以下是修改后的代码:

function bmi(weight, height) { let msg = weight / (height * height); if (msg <= 18.5) { return "Underweight"; } else if (msg <= 25.0) { return "Normal"; } else if (msg <= 30.0) { return "Overweight"; } else { return "Obese"; } }

用javascript Write function bmi that calculates body mass index bmi = weight height2if bmi = 185 return Underweightif bmi = 250 return Normalif bmi = 300 return Overweightif bmi 30 return Obese le

原文地址: https://www.cveoy.top/t/topic/8ht 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录