我正在尝试计算升力器的威尔克斯分数和公式我正在使用调用男性和女性升降机之间的方程式中使用的不同变量。为什么它不断回归男性公式而不是女性版本。
<div id="wilks">
<select id="gender">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
<br>
<input id="big3Total" type="text" placeholder="Big 3 Total">
<input id="bodyWeight" type="text" name="" placeholder="Bodyweight in Lbs">
<button onclick="wilks()">Calculate</button>
<p id="wilksScore"></p>
</div>
<script>
function wilks() {
var gender = document.getElementById("gender");
if ( gender == 'male') {
a = -216.0475144;
b = 16.2606339;
c = -0.002388645;
d = -0.00113732;
e = 7.01863E-06;
f = -1.291E-08;
} else {
a = 594.31747775582;
b = -27.23842536447;
c = 0.82112226871;
d = -0.00930733913;
e = 4.731582E-05;
f = -9.054E-08;
}
var big3Total = document.getElementById('big3Total').value * 0.453592;
var bodyWeight = document.getElementById('bodyWeight').value * 0.453592;
var wilks = big3Total * (500 / (a + (b * bodyWeight) + (c * Math.pow(bodyWeight, 2)) + (d * Math.pow(bodyWeight, 3)) + (e * Math.pow(bodyWeight, 4)) + (f * Math.pow(bodyWeight, 5))));
document.getElementById('wilksScore').innerHTML = "Your Wilks score is: " + wilks.toFixed(2);
}
</script>
答案 0 :(得分:1)
尝试替换此行:
var gender = document.getElementById("gender");
以下内容:
var gender = document.getElementById("gender").value;
答案 1 :(得分:0)
每当你使用dom api请求任何dom元素时,你得到的是一个html节点。 document.getElementById
返回了选择节点。
var gender = document.getElementById("gender");
console.log(gender) // outputs the node of type HTMLSelectElement
console.log(HTMLSelectElement[Symbol.hasInstance](gender)); // true
gender.value; // gives you the value of the current selected option
您实际在做的是将select
节点与"male"
进行比较,该节点将始终评估为false
你的测试应该是
if ( gender.value === ... ) {
// do something
}