BMI 计算器希望有一个 parseInt() 函数

BMI caculator want to have a parseInt() function

本文关键字:函数 parseInt 有一个 计算器 希望 希望有 BMI      更新时间:2023-09-26

我刚刚得到了下面的代码,我发现我需要做parseInt()函数。这意味着我需要使用此函数为我的 BMI 答案找到整数答案。

<!DOCTYPE html>
<html>
<head>
    <title> 
        Calculate your BMI
    </title>

<script type=text/javascript>
function CalculateBmi(){
var weight= document.getElementsByName('weight')[0].value;
var height= document.getElementsByName('height')[0].value;
if(weight>0 && height>0){
var finalBMI=(weight/(height*height))*703;
document.getElementsByName('BMI')[0].value=finalBMI;
}
}
</script>
</head>

<body>
    <form name="Form">
    weight in pounds
    <input type="text"  name="weight" />
        <br/>
    height in inches
    <input type="text" name="height"/>
        <br/>
    <input type="button" value="calculate BMI" onclick="CalculateBmi()">
        <br />
    BMI result
    <input type="text" name="BMI"/>
    </form>
</body>
</html>

上面的代码是我所做的,我尝试将 () 放入 co,例如

document.getElementsByName('BMI')[0].value=ParseInt(finalBMI);

但我确信我错过了一些东西。

var weight= parseInt(document.getElementsByName('weight')[0].value, 10);
var height= parseInt(document.getElementsByName('height')[0].value, 10);

下次,请向我们展示您在问题中的尝试!