Created
October 23, 2013 14:49
-
-
Save KenjiOhtsuka/7120232 to your computer and use it in GitHub Desktop.
BMI と 基礎代謝 の計算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ブログにあったコードをこっちで書いてみた。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
margin: 0; | |
padding: 0; | |
border: 0; | |
} | |
body { | |
font: 12px sans-serif; | |
background-color: LemonChiffon; | |
} | |
input, textarea { | |
border: 1px solid; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="BodyCalculation" name="BodyCalculation"> | |
<fieldset> | |
<input type="radio" value="0" name="inputGender" id="inputMan" />男性 | |
<input type="radio" value="1" name="inputGender" id="inputWoman" />女性 | |
</fieldset> | |
<label for="inputAge">年齢: </label> | |
<input type="text" size="5" maxlength="3" id="inputAge" style="text-align:right;" />歳<br /> | |
<label for="inputHeight">身長: </label> | |
<input type="text" size="5" maxlength="5" id="inputHeight" style="text-align:right;" />cm<br /> | |
<label for="inputWeight">体重: </label> | |
<input type="text" size="5" maxlength="5" id="inputWeight" style="text-align:right;" />kg<br /> | |
<input type="button" onClick="calculateBodyMeasure()" value="計算する" /> | |
<input type="reset" value="クリア"/><br /> | |
<textarea id="resultText" name="resultText" rows="5" cols="40"></textarea> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateBodyMeasure() { | |
var resultText = ''; | |
var inputAge = document.getElementById("inputAge").value; | |
var inputHeight = document.getElementById("inputHeight").value; | |
var inputWeight = document.getElementById("inputWeight").value; | |
if (isNaN(inputAge) || inputAge == '' || | |
isNaN(inputHeight) || inputHeight == '' || inputHeight == 0 || | |
isNaN(inputWeight) || inputWeight == '') { | |
resultText = '数値を入力してね。'; | |
} else { | |
var resultBMI = inputWeight * 10000 / inputHeight / inputHeight; | |
resultBMI = Math.floor(resultBMI * 100) / 100; | |
var resultText = ''; | |
if (resultBMI > 26) { | |
resultText = 'ふとりすぎ'; | |
} else if (resultBMI > 24) { | |
resultText = 'ふとりぎみ'; | |
} else if (resultBMI > 20) { | |
resultText = '標準'; | |
} else if (resultBMI > 18) { | |
resultText = 'やせぎみ'; | |
} else { | |
resultText = 'やせすぎ'; | |
} | |
resultText = resultText.concat('BMIは ', resultBMI, '(', resultText, ') です。'); | |
var baseNutrition = 0; | |
if (document.getElementById('inputMan').checked) { | |
baseNutrition = 66 + 13.7 * inputWeight + 5 * inputHeight - 6.8 * inputAge; | |
} else if (document.getElementById('inputWoman').checked) { | |
baseNutrition = 665 + 9.6 * inputWeight + 1.7 * inputHeight - 7 * inputAge; | |
} | |
baseNutrition = Math.floor(baseNutrition * 100) / 100; | |
if (baseNutrition != 0) { | |
resultText = resultText.concat('\n基礎代謝は ', baseNutrition, 'kcal です。'); | |
} | |
var idealWeight = Math.floor(22.2 * inputHeight * inputHeight / 100) / 100; | |
resultText = resultText.concat('\n\nBMIから求めた理想の体重は ', idealWeight, 'kg です。'); | |
} | |
document.getElementById("resultText").value = resultText; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment