gpt4 book ai didi

javascript - 哇哇咔嚓! "Your BMI calculation is not correct"

转载 作者:行者123 更新时间:2023-12-02 23:32:23 25 4
gpt4 key购买 nike

我正在研究BMI计算器技术评估,但我陷入了使用公式的阶段。计算 BMI 的指令为:

Instruction 1:

Each user's height is expressed in feet, so the calculation needs to first convert it to meters. HINT: multiple height by 0.3048.

Instruction 2:

BMEye calculates BMI with an advanced algorithm! BMEye has the notion of countries with the healthiest diet and they are Chad, Sierra Leone, Mali, Gambia, Uganda, Ghana, Senegal, Somalia, Ivory Coast, and Isreal . If the user is from any of these countries, then the calculated BMI figure is multipled by 0.82, bringing it down a little.

Last instruction:

Following the guide and hints above, get computeBMI to use the user's weight, height, and country to calculate and return the BMI value for the user.

我尝试做的事情:

我尝试在本地编辑器 sublime text 中运行代码,它可以正确计算 BMI,但是当我将代码放在运行评估的平台 Google 成绩跟踪器上时,它会抛出错误,提示“您的 BMI 计算不正确! ”

有人可以帮我解决这个错误吗?下面是一个函数,它通过获取高度、体重和国家/地区来接收用户的对象以帮助计算。

const computeBMI = ({weight, height, country}) => {
const LowBMIcountries = ["Chad", "Sierra Leone", "Mali", "Gambia",
"Uganda", "Ghana", "Senegal", "Somalia", "Ivory Coast", "Israel"];
const bmiRate = 0.82;

let ConvertHeight = height * 0.3048;

let BMI = weight / Math.pow(ConvertHeight,2);

if (LowBMIcountries.includes(country)) {
BMI *= bmiRate;
}
return Math.round(BMI, 2);

};

最佳答案

这个问题没有提到舍入,更不用说您对 Math.round 的使用是不正确的。 Math.round 接受一个参数并四舍五入到最接近的整数。如果您想要两位小数,请使用 toFixed(2)

关于javascript - 哇哇咔嚓! "Your BMI calculation is not correct",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56442888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com