Skip to content

Added a new project - (113 - BMI Calculator) #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 113 - BMI Calculator/assets/bmi calculator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions 113 - BMI Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!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="bigcontainer">
<div class="container" id="calculator">
<h2>BMI Calculator</h2>
<label for="heightFeet">Height (Feet):</label>
<input type="number" id="heightFeet" min="0" placeholder="Feet" />
<label for="heightInches">Height (Inches):</label>
<input type="number" id="heightInches" min="0" placeholder="Inches" />
<label for="weightKgs">Weight (Kgs):</label>
<input
type="number"
id="weightKgs"
min="0"
placeholder="Weight in Kgs"
/>
<button id="calculateBtn">Calculate BMI</button>
<div id="result"></div>
</div>
<div class="container" id="info">
<h2>BMI Information</h2>
<p>BMI Categories:</p>
<ul>
<li>Underweight: BMI less than 18.5</li>
<li>Normal weight: BMI 18.5–24.9</li>
<li>Overweight: BMI 25–29.9</li>
<li>Obesity: BMI 30 or more</li>
</ul>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions 113 - BMI Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
document
.getElementById("calculateBtn")
.addEventListener("click", function () {
var heightFeet =
parseFloat(document.getElementById("heightFeet").value) || 0;
var heightInches =
parseFloat(document.getElementById("heightInches").value) || 0;
var weightKgs =
parseFloat(document.getElementById("weightKgs").value) || 0;

var totalHeightMeters = (heightFeet * 12 + heightInches) * 0.0254;
var bmi = weightKgs / (totalHeightMeters * totalHeightMeters);



var resultDiv = document.getElementById("result");
if(isNaN(bmi) || isNaN(weightkgs) || (isNan(heightFeet) && isNan(heightInches))){
resultDiv.innerHTML="";
}
else{
resultDiv.innerHTML = "Your BMI: " + bmi.toFixed(2) + "<br>";
}

if (bmi < 18.5) {
resultDiv.innerHTML += "Category: Underweight";
} else if (bmi >= 18.5 && bmi <= 24.9) {
resultDiv.innerHTML += "Category: Normal weight";
} else if (bmi >= 25 && bmi <= 29.9) {
resultDiv.innerHTML += "Category: Overweight";
} else if (bmi>29.9){
resultDiv.innerHTML += "Category: Obesity";
}
else{
resultDiv.innerHTML +="Please enter data."
}
});
57 changes: 57 additions & 0 deletions 113 - BMI Calculator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
body {
font-family: Arial, sans-serif;
background-color: #141b41;
color: #fff;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
width: 300px;
margin: 20px;
padding: 20px;
padding-right: 35px;
background-color: #1f2957;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.bigcontainer {
margin: auto;
display: flex;
flex-direction: column;
align-items: center;
}
#calculator,
#info {
display: inline-block;
width: calc(50% - 5px);
vertical-align: top;
}
#info {
padding-top: 1px;
}
#calculator input {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: none;
border-radius: 5px;
background-color: #253966;
color: #fff;
}
#calculateBtn {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
background-color: #0047ab;
color: #fff;
cursor: pointer;
}
#result {
margin-top: 20px;
}

Binary file added 30DaysOfJavaScript/assets/113.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ Repo containing all the projects made in 30 Days while completing the <b>30 Days
| 109 | [Number Facts](https://30daysofjs.netlify.app/145%20-%20Number%20Facts/) |
| 110 | [Pixel to em Converter](https://30daysofjs.netlify.app/110%20-%20Pixel%20to%20em%20Converter/) |
| 111 | [Luminosity Particle Js](https://30daysofjs.netlify.app/141%20-%20Luminosity%20Particle%20Js/) |
| 112 | [Maze Game](https://30daysofjs.netlify.app/112%20-%20Maze%20Game/) |
| 112 | [Maze Game](https://30daysofjs.netlify.app/112%20-%20Maze%20Game/) |
| 113 | [BMI Calculator](https://30daysofjs.netlify.app/113%20-%20BMI%20Calculator/) |

</td><td>
</td></tr></table>
Expand Down
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,16 @@ <h4>Maze Game</h4>
</a>
</div>

<div class="item">
<img src="30DaysOfJavaScript/assets/113.png" alt="BMI Calculator">
<h4>BMI Calculator</h4>
<a target="_blank"
href="https://github.com/swapnilsparsh/30DaysOfJavaScript/tree/master/113%20-%20BMI%20Calculator%20">
<i class="fa-brands fa-square-github"></i>
<a target="_blank" href="113 - BMI Calculator/index.html"><i class="fa-solid fa-link"></i> </a>
</a>
</div>

</div>
<!-- Main Section End -->

Expand Down