無法在JSFiddle中打印任何內容,儘管一切看起來都適合我。我不確定HTML爲什麼不顯示答案,但歡迎任何幫助。謝謝!Javascript BMI計算器
HTML:
<h2>BMI Calculator</h2>
<p>
Enter your weight in pounds:
<input type="text" id="weight">
</p>
<p>
Enter your height in inches:
<input type="text" id="height">
</p>
<input type="button" onclick="bmiCalculator()" value="calculate">
<p id="output"></p>
的Javascript:
function bmiCalculator() {
var weight = Number(document.getElementById("weight").value);
var height = Number(document.getElementById("height").value);
var finalWeight = weight * .45;
var finalHeight = height * .025;
var BMI = (finalWeight/Math.pow(finalHeight, 2));
document.getElementById("output").innerHTML = BMI;
}
始終使用控制檯/調試工具。它會爲你節省很多頭痛。 –