-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmi.html
More file actions
102 lines (90 loc) · 2.66 KB
/
bmi.html
File metadata and controls
102 lines (90 loc) · 2.66 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
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI Calculator</title>
<style>
body{
margin: 0;
background: linear-gradient(to left bottom, lightgreen, lightblue);
display: flex;
min-height: 100vh;
justify-content: center;
align-items: center;
font-family: 'Courier New', Courier, monospace;
}
.container{
background: rgba(255,255,255, .3);
padding: 20px;
display: flex;
flex-direction: column;
border-radius: 5px;
box-shadow: 0 10px 10px rgba(0,0,0,.3);
margin: 5px;
}
.heading{
font-size: 30px;
}
.input{
padding: 10px 20px;
font-size: 18px;
background: rgba(255,255,255, .4);
border-color: rgba(255,255,255, .5);
margin: 10px;
}
.btn{
background-color: lightgreen;
border: none;
padding: 10px 20px;
border-radius: 5px;
margin: 10px;
font-size: 20px;
box-shadow: 0 0 4px rgba(0,0,0,.3);
cursor: pointer;
}
.btn:hover{
box-shadow: 0 0 8px rgba(0,0,0,.3);
transition: all 300ms ease;
}
.info-text{
font-size: 20px;
font-weight: 500;
}
</style>
</head>
<body>
<div class="container">
<h1 class="heading">Body Mass Index (BMI) Calculator</h1>
Your Height (cm):
<input type="number" class="input" id="height" value="180" placeholder="Enter your height in cm">
Your Weight (kg):
<input type="number" class="input" id="weight" value="80" placeholder="Enter your weight in kg">
<button class="btn" id="btn">Compute BMI</button>
<input disabled type="text" class="input" id="bmi-result">
<h4 class="info-text">Weight Condition: <span id="weight-condition"></span></h4>
</div>
<script>
const btnEl = document.getElementById("btn");
const bmiInputEl = document.getElementById("bmi-result");
const weightConditionEl = document.getElementById("weight-condition");
function calculateBMI() {
const heightValue = document.getElementById("height").value / 100;
const weightValue = document.getElementById("weight").value;
const bmiValue = weightValue / (heightValue * heightValue);
bmiInputEl.value = bmiValue;
if (bmiValue < 18.5) {
weightConditionEl.innerText = "Under weight";
} else if (bmiValue >= 18.5 && bmiValue <= 24.9) {
weightConditionEl.innerText = "Normal weight";
} else if (bmiValue >= 25 && bmiValue <= 29.9) {
weightConditionEl.innerText = "Overweight";
} else if (bmiValue >= 30) {
weightConditionEl.innerText = "Obesity";
}
}
btnEl.addEventListener("click", calculateBMI);
</script>
</body>
</html>