BMI計算のプログラムを一度作成してみたのですが
javascript
1function calcBMI() { 2 let weight = document.getElementsByClassName("weight"); 3 let height = document.getElementsByClassName("height"); 4 let weightValue = weight.value; 5 let heightValue = height.value; 6 let result = weightValue / Math.pow(heightValue/100, 2); 7 let showResult = document.getElementById("showResult"); 8 showResult.textContent = "BMI計算結果は" + result; 9}
html
1<!DOCTYPE html> 2<html lang="ja"> 3 <head> 4 <meta charset="utf-8"> 5 <title>BMI測定</title> 6 </head> 7 <body> 8 <h1>BMI計算</h1> 9 <input type="text" class="weight" placeholder="あなたの体重を入力してください"><br> 10 <input type="text" class="height" placeholder="あなたの身長を入力してください"> 11 <p> 12 <button type="button" onclick="calcBMI()">BMI計算</button> 13 </p> 14 <p id="showResult"></p> 15 <script type="text/javascript" src="calcBMI.js"></script> 16 </body> 17</html> 18
このように組み立てると、bmi計算結果がNaNと出てしまいます。原因がわかりません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/18 18:05