Skip to content

Commit 2e76424

Browse files
committed
add project: BMI Calculator
1 parent 9bd3079 commit 2e76424

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

BMI-Calculator/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# BMI Calculator
2+
3+
**A simple Body Mass Index (BMI) calculator built using HTML, CSS, and JavaScript.**
4+
This calculator helps users calculate their BMI by entering their height and weight and also provides a guide for interpreting the result.
5+
6+
### Functionalities
7+
- **BMI Calculation**: Calculates the Body Mass Index (BMI) based on height in centimeters and weight in kilograms.
8+
- **Input Validation**: Ensures valid numeric inputs for height and weight, providing feedback for invalid inputs.
9+
- **BMI Range Guide**: Displays a guide for interpreting BMI ranges (Underweight, Normal, Overweight).
10+
11+
## Description
12+
This is a basic web-based BMI calculator that allows users to input their height and weight to calculate their BMI. The BMI is calculated using the following formula:
13+
14+
**BMI = Weight (kg) / (Height (cm) * Height (cm) / 10000)**
15+
16+
Where:
17+
- **Weight (kg)** is the person's weight in kilograms.
18+
- **Height (cm)** is the person's height in centimeters.
19+
20+
The result is displayed on the screen along with a color-coded message based on the calculated value. The app also shows a BMI weight guide to help users understand where their BMI falls in terms of underweight, normal, and overweight categories.
21+
22+
## Prerequisites
23+
No external libraries or packages are required for this project. It only uses HTML, CSS, and vanilla JavaScript.
24+
25+
## Installing Instructions
26+
1. Clone the repository:
27+
```bash
28+
git clone https://github.com/your-username/All-In-One-Javascript-Projects.git
29+
```
30+
2. Navigate to the project directory:
31+
```bash
32+
cd All-In-One-Javascript-Projects/BMI-Calculator
33+
```
34+
3. Open the `index.html` file in a web browser:
35+
36+
## Author
37+
- Aman Kumar (@[king04aman](https://github.com/king04aman))

BMI-Calculator/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<link rel="stylesheet" href="style.css">
8+
<title>BMI Calculator</title>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<h1>BMI Calculator</h1>
13+
<form id="bmiForm">
14+
<p>
15+
<label for="height">Height in CM: </label>
16+
<input type="text" id="height" placeholder="Enter height">
17+
</p>
18+
<p>
19+
<label for="weight">Weight in KG: </label>
20+
<input type="text" id="weight" placeholder="Enter weight">
21+
</p>
22+
<button type="submit">Calculate</button>
23+
</form>
24+
<div id="results"></div>
25+
<div id="weight-guide">
26+
<h3>BMI Weight Guide</h3>
27+
<p>Underweight: Less than 18.6</p>
28+
<p>Normal Range: 18.6 - 24.9</p>
29+
<p>Overweight: Greater than 24.9</p>
30+
</div>
31+
</div>
32+
<script src="main.js"></script>
33+
</body>
34+
</html>

BMI-Calculator/main.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const form = document.querySelector('form');
2+
3+
form.addEventListener('submit', function(e) {
4+
e.preventDefault(); // Prevent form submission
5+
6+
const height = parseFloat(document.querySelector('#height').value);
7+
const weight = parseFloat(document.querySelector('#weight').value);
8+
const results = document.querySelector('#results');
9+
10+
// Validate height and weight
11+
if (!height || height <= 0 || isNaN(height)) {
12+
results.innerHTML = "Please provide a valid height in cm";
13+
} else if (!weight || weight <= 0 || isNaN(weight)) {
14+
results.innerHTML = "Please provide a valid weight in kg";
15+
} else {
16+
const bmi = (weight / ((height * height) / 10000)).toFixed(2);
17+
results.innerHTML = `<span>Your BMI: ${bmi}</span>`;
18+
}
19+
});

BMI-Calculator/style.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
height: 100vh;
6+
margin: 0;
7+
background-color: #f0f0f0;
8+
font-family: Arial, sans-serif;
9+
}
10+
11+
.container {
12+
width: 400px;
13+
background-color: #ffeb3b;
14+
padding: 20px;
15+
border-radius: 10px;
16+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
17+
text-align: center;
18+
}
19+
20+
h1 {
21+
color: #333;
22+
margin-bottom: 20px;
23+
}
24+
25+
input[type="text"] {
26+
width: 80%;
27+
height: 35px;
28+
margin: 10px 0;
29+
border: 1px solid #ccc;
30+
border-radius: 5px;
31+
padding-left: 10px;
32+
font-size: 16px;
33+
}
34+
35+
#results {
36+
font-size: 24px;
37+
color: #007bff;
38+
margin-top: 20px;
39+
}
40+
41+
#weight-guide {
42+
margin-top: 30px;
43+
}
44+
45+
button {
46+
width: 80%;
47+
height: 45px;
48+
background-color: #007bff;
49+
color: #fff;
50+
border: none;
51+
border-radius: 5px;
52+
font-size: 20px;
53+
cursor: pointer;
54+
margin-top: 20px;
55+
}
56+
57+
button:hover {
58+
background-color: #0056b3;
59+
}
60+
61+
#weight-guide p {
62+
font-size: 14px;
63+
}

0 commit comments

Comments
 (0)