-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathBMI Calculator
59 lines (59 loc) · 1.58 KB
/
BMI Calculator
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
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="calculator-container">
<h1>BMI Calculator</h1>
<form id="bmiForm">
<input type="number" id="weightInput" placeholder="Enter weight in kg" required>
<input type="number" id="heightInput" placeholder="Enter height in cm" required>
<button type="submit">Calculate</button>
</form>
<p id="bmiDisplay">Your BMI: </p>
</div>
<script src="script.js"></script>
</body>
</html>
CSS:
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.calculator-container {
text-align: center;
background-color: #f0f0f0;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
form {
display: flex;
flex-direction: column;
gap: 10px;
}
input, button {
padding: 10px;
font-size: 16px;
}
p {
font-size: 18px;
margin: 0;
}
JavaScript:
document.getElementById('bmiForm').addEventListener('submit', function(event) {
event.preventDefault();
const weight = parseFloat(document.getElementById('weightInput').value);
const height = parseFloat(document.getElementById('heightInput').value) / 100;
const bmi = (weight / (height * height)).toFixed(2);
document.getElementById('bmiDisplay').textContent = `Your BMI: ${bmi}`;
});