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

Awwww snap! "Your BMI calculation is not correct"

我正在做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 平台上的成绩跟踪器时 运行评估,它会抛出一个错误 "Your BMI calculation is not correct!"

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

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).

几天后,我想出了这个具有挑战性的问题的正确答案,我知道这对以后的其他人会有用。

const computeBMI = ({weight, height, country}) => {

const countries = ["Chad", "Sierra Leone", "Mali", "Gambia", "Uganda",              
          "Ghana", "Senegal", "Somalia", "Ivory Coast", "Isreal"];

          const hm = height * 0.3048;
          const ratio = (countries.includes(country) ? 0.82 : 1);

      const BMI = (weight / (hm * hm)) * ratio;
          return parseFloat(BMI).toFixed(1);

           }; 

学习下面..

entervar computeBMI = function({weight,height,country}) {



    const bmiScale = 0.82;
    let feetToMeter = 0.3048;


     const countries = ['Chad','Sierra Leone','Mali','Gambia','Uganda',
              'Ghana','Senegal','Somalia','Ivory Coast','Isreal'];
   const heightinmeter = (height * feetToMeter);

    let bim = ((weight)/(heightinmeter ** 2));


    if(countries.includes(country)) {bim = bim * bmiScale}

    var fixednum = bim.toFixed(1);

    return fixednum;


  }