-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmybmi.html
More file actions
100 lines (70 loc) · 2.55 KB
/
mybmi.html
File metadata and controls
100 lines (70 loc) · 2.55 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<html>
<head>
<title>BMI Calculator</title>
<script type="text/javascript">
// only functions should be put here.
// if you have global statements, they should be put in
// a script tag at the end of the body.
// If you mix functions and global statements in one external js file
// it should be referenced using a script tag put in the end of the body
function computeBMI()
{
//Obtain user inputs
var height=document.getElementById("height").value;
var weight=document.getElementById("weight").value;
//Convert all units to metric
height/=39.3700787;
weight/=2.20462;
//Perform calculation
var BMI=weight/Math.pow(height,2);
//Display result of calculation
document.getElementById("output").innerHTML=Math.round(BMI*100)/100;
if (BMI<18.5)
annotation = "Underweight";
if (BMI>=18.5 && BMI<=25)
annotation = "Normal";
if (BMI>=25 && BMI<=30)
annotation = "Obese";
if (BMI>30)
annotation = "Overweight";
// Display annotation
document.getElementById("comment").innerHTML = annotation;
document.getElementById("test").innerHTML = "You are" + height +"meters";
}
</script>
</head>
<style>
button, body{
background-color: white;
font-size:20pt;
}
</style>
<body>
<a href="http://www.whathealth.com/bmi/formula.html"> Click here for formula
</a>
<div>Body Mass Index Calculator</div>
<div>Enter your height in inches: <input type="text" id="height"/>
</div>
<div>Enter your weight in pounds: <input type="text" id="weight"/>
</div>
<div>
<button onclick="computeBMI();"> ComputeBMI obtrusive</button> <!-- this is obtrusive -->
<button id="b1";"> ComputeBMI unobtrusive </button> <!-- this is unobtrusive, see below javascript-->
</div>
<div> Your BMI is: <span id="output">?</span> </div>
<div> Your are: <span id="comment">?</span> </div>
<div> Testing <span id="test">?</span> </div>
<script type="text/javascript">
// only functions should be put here.
// if you have global statements, they should be put in
// a script tag at the end of the body.
// If you mix functions and global statements in one external js file
// it should be referenced using a script tag put in the end of the body
var b = document.getElementById('b1');
b.onclick = function() {
alert('Hello Hartwick');
computeBMI();
}
</script>
</body>
</html>