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

标签 javascript es6-modules

我正在研究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/

相关文章:

node.js - 如何在 Node.js 中使用 ES6 导入?

javascript - 当在 Chrome 和 Firefox 中声明 DOCTYPE 时,Google Map API 不起作用

javascript - 剑道网格更新窗口缩放效果损坏

node.js - 如何在 Node REPL 中使用 "import"

javascript - 在 TC39 'ES6' 导入中导入模块时是否可以运行模块的设置函数?

node.js - module.exports=require ('other' ) 和临时变量有什么区别?

reactjs - 如何将函数中的假 API 包含到 React.JS 应用程序中

JavaScript 使用正则表达式和偏移量开始

javascript - 间隔内更新的第一个 d3 转换未转换

javascript - 分组表行的 CSS 样式