-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmi_cal.html
More file actions
121 lines (110 loc) · 3.49 KB
/
bmi_cal.html
File metadata and controls
121 lines (110 loc) · 3.49 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>BMI Calculator</title>
<style>
body {
font-family: 'Poppins', sans-serif;
background-image: url('https://img.freepik.com/premium-photo/fitness-equipment-workout_522560-19444.jpg');
background-size: cover;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.calculator {
background-color: rgba(255, 255, 255, 0.8);
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
padding: 32px;
text-align: center;
width: 320px;
}
.calculator h2 {
color: #4c4e56;
font-size: 32px;
font-weight: 700;
margin-bottom: 32px;
}
.calculator input {
background-color: #f6f8fa;
border: 1px solid #c2c2c2;
border-radius: 4px;
margin-bottom: 16px;
padding: 12px;
width: 90%;
font-size: 18px;
}
.calculator button {
background-color: #4caf50;
border: none;
border-radius: 4px;
color: #fff;
font-size: 18px;
font-weight: 700;
padding: 12px 20px;
text-transform: capitalize;
cursor: pointer;
transition: background-color 0.2s ease;
}
.calculator button:hover {
background-color: #449747;
}
#result {
margin-top: 32px;
font-size: 24px;
font-weight: 700;
word-wrap: break-word;
}
.health-goal {
font-size: 20px;
font-weight: bold;
}
.health-goal-muscle-gain {
color: orange;
}
</style>
</head>
<body>
<div class="calculator">
<h2>BMI Calculator</h2>
<form id="bmi-form">
<input type="number" id="height" placeholder="Your height (cm)">
<input type="number" id="weight" placeholder="Your weight (kg)">
<input type="number" id="age" placeholder="Your age">
<button type="submit" id="calculate-bmi">Calculate BMI</button>
</form>
<div id="result"></div>
</div>
<script src="app.js"></script>
<script>
document.getElementById('bmi-form').addEventListener('submit', function (e) {
e.preventDefault();
const height = document.getElementById('height').value;
const weight = document.getElementById('weight').value;
const age = document.getElementById('age').value;
const bmi = (weight / Math.pow(height / 100, 2)).toFixed(1);
let result = '';
let p = '';
if (bmi < 18.5) {
result = 'You are underweight.';
p = '<span class="health-goal health-goal-muscle-gain">FITNESS GOAL: Muscle Gain</span>';
document.getElementById('result').style.color = 'green';
} else if (bmi >= 18.5 && bmi <= 24.9) {
result = 'You are a healthy weight';
p = '<span class="health-goal health-goal-muscle-gain">FITNESS GOAL: Muscle Gain</span>';
document.getElementById('result').style.color = 'green';
} else if (bmi > 24.9) {
result = 'You are overweight';
p = '<span class="health-goal health-goal-muscle-gain">FITNESS GOAL: Weight Loss</span>';
document.getElementById('result').style.color = 'green';
}
document.getElementById('result').innerHTML = `Your BMI is ${bmi}, ${result}<br><br>${p}`;
});
</script>
</body>
</html>