人体BMI指数计算JS代码版

BMI指数指的是人体的体重指数,是反映人体体重是正常、超重、肥胖或者消瘦的一个重要的指标。

代码如下

function calculateBMI(weight, height) {
  const heightInMeters = height / 100;
  const bmi = weight / (heightInMeters * heightInMeters);
  return bmi.toFixed(2);
}

const weight = 70; // in kg
const height = 170; // in cm

const bmi = calculateBMI(weight, height);

console.log(`Your BMI is ${bmi}`);
THE END