-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (93 loc) · 2.45 KB
/
index.html
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
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced BMI Calculator</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
#calculator {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
text-align: center;
}
label {
display: block;
margin-bottom: 8px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
}
button {
background-color: #4caf50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="calculator">
<h1>BMI Calculator</h1>
<label for="weight">Weight:</label>
<input type="number" id="weight" placeholder="Enter weight" step="any">
<label for="height">Height:</label>
<input type="number" id="height" placeholder="Enter height" step="any">
<label for="unit">Unit:</label>
<select id="unit">
<option value="metric">Metric (kg, cm)</option>
<option value="imperial">Imperial (lbs, in)</option>
</select>
<button onclick="calculateBMI()">Calculate BMI</button>
<div id="result"></div>
</div>
<script>
function calculateBMI() {
var weight = parseFloat(document.getElementById('weight').value);
var height = parseFloat(document.getElementById('height').value);
var unit = document.getElementById('unit').value;
if (isNaN(weight) || isNaN(height)) {
alert('Please enter valid values for weight and height.');
return;
}
if (unit === 'imperial') {
// Convert weight from pounds to kilograms
weight *= 0.453592;
// Convert height from inches to meters
height *= 0.0254;
}
var bmi = weight / (height * height);
displayResult(bmi);
}
function displayResult(bmi) {
var resultElement = document.getElementById('result');
resultElement.innerHTML = 'Your BMI is: ' + bmi.toFixed(2);
}
</script>
</body>
</html>