简体   繁体   English

为什么会恢复正常体重

[英]Why does it return normal weight

This BMI calculator returns it right for the underweight and the normal weight, but when result is bigger than 25 it returns the normal weight option, when it's supposed to return the overweight option.这个 BMI 计算器返回正确的体重不足和正常体重,但是当result大于 25 时它返回正常体重选项,当它应该返回超重选项时。 How can I fix it?我该如何解决?

 function bmiCalculator(weight, height) { var weight = prompt("How much do you weight?") var height = prompt("How tall are you? ") result = weight / Math.pow(height, 2) if (result < 18.5) { return("Your BMI is " + result + ", so you are underweight") } else if (result >= 18.5 || result <= 24.9) { return("Your BMI is " + result + ", so you have a normal weight") } else if (result >= 25) { return("Your BMI is " + result + ", so you are overweight") } } console.log(bmiCalculator())

You just need to change the ||你只需要改变 || to an &&到一个&&

Instead of:代替:

} else if (result >= 18.5 || result <= 24.9) {

Do:做:

} else if (result >= 18.5 && result <= 24.9) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM