gpt4 book ai didi

javascript - 用于计算 bmr 的 if else 语句

转载 作者:行者123 更新时间:2023-12-03 08:25:07 24 4
gpt4 key购买 nike

我正在开展一个涉及计算 bmr 的学校项目,当我调用此函数时,我不断收到引用错误。

<script>
function calbmr(){
var height, weight, age;
var gender;

age = parseFloat(document.bmiform.age.value)
height = parseFloat(document.bmiform.height.value);
weight = parseFloat(document.bmiform.weight.value);

if (document.getElementById('Male').checked) {
gender = (66 + (9.6 * weight) + (1.8 * height) – (4.7 * age));
alert(gender);
}


else if (document.getElementById('Female').checked) {
gender = (655 + (13.7 * weight) + (5 * height) – (6.8 * age));
alert(gender);
}

else {

alert("please select a gender");
}
}
</script>

但是当我将代码更改为它时,它会返回结果

if (document.getElementById('Male').checked) {
gender = "Male"
alert(gender);
}


else {
if (document.getElementById('Female').checked) {
gender = "Female";
alert(gender);
}

最佳答案

您的代码中有两个错误的 - 符号:

if (document.getElementById('Male').checked) {
gender = (66 + (9.6 * weight) + (1.8 * height) - (4.7 * age));
// ^
alert(gender);
} else if (document.getElementById('Female').checked) {
gender = (655 + (13.7 * weight) + (5 * height) - (6.8 * age));
// ^
alert(gender);
}

关于javascript - 用于计算 bmr 的 if else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33587025/

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