2012年1月7日 星期六

計算BMI工具

體重過輕 (Under weight)BMI < 18.5
體重正常 (Normal weight)18.5 ≤ BMI <24
體重過重 (Over weight)24 ≤ BMI < 27
輕度肥胖 (Mildly obese)27 ≤ BMI < 30
中度肥胖 (Moderately obese)30 ≤ BMI < 35
重度肥胖 (Severe obesity)35 ≤ BMI

Height (cm):
Weight (kg):



後記:
雖然是很簡單的程式,不過因為需要用所以隨手寫了下,畢竟最近體重被盯很緊...( 艸)

原始碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<table>
<tr><td>體重過輕 (Under weight)</td><td>BMI &lt; 18.5</td></tr>
<tr><td>體重正常 (Normal weight)</td><td>18.5 &le; BMI &lt;24</td></tr>
<tr><td>體重過重 (Over weight)</td><td>24 &le; BMI &lt; 27</td></tr>
<tr><td>輕度肥胖 (Mildly obese)</td><td>27 &le; BMI &lt; 30</td></tr>
<tr><td>中度肥胖 (Moderately obese)</td><td>30 &le; BMI &lt; 35</td></tr>
<tr><td>重度肥胖 (Severe obesity)</td><td>35 &le; BMI</td></tr>
</table>
<br />
Height (cm): <input type="text" id="hhboxy" /><br />
Weight (kg): <input type="text" id="whboxy" /><br />
<button id="countboxy">Count</button><br />
<span id="bmiboxy"></span>
<script type="text/javascript">
var bmiboxy = new function() {
return {
json : {
0 : "體重過輕 (Under weight)",
185 : "體重正常 (Normal weight)",
240 : "體重過重 (Over weight)",
270 : "輕度肥胖 (Mildly obese)",
300 : "中度肥胖 (Moderately obese)",
350 : "重度肥胖 (Severe obesity)"
},
count : function() {
var height = document.getElementById('hhboxy').value;
var weight = document.getElementById('whboxy').value;
var bmi = weight/Math.pow(height/100 ,2);
for(var key in this.json)
if(bmi >= (key/10))
var explain = this.json[key];
document.getElementById('bmiboxy').innerHTML = "BMI=" + bmi.toPrecision(5) + ", " + explain;
}
};
};
document.getElementById('countboxy').onclick = function() {
bmiboxy.count();
};
</script>

沒有留言: