Skip to content
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

Added Blood Alcohol Content Calculator #1372

Merged
merged 12 commits into from
Jun 23, 2024
16 changes: 16 additions & 0 deletions Calculators/Blood-Alcohol-Content-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# <p align="center">Blood Alcohol Content Calculator</p>

## Description :-

This calculator calculates the blood alcohol content based on the inputs (number of drinks, weight, gender, and time since the last drink) given by the user.

## Tech Stacks :-

- HTML
- CSS
- JavaScript
- Bootstrap

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/142327526/313f36a1-6353-41d9-a411-61a396cd7650)
41 changes: 41 additions & 0 deletions Calculators/Blood-Alcohol-Content-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="style.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Blood Alcohol Content Calculator</title>
</head>
<body>
<div class="bg d-flex justify-content-center align-items-center">
<div class="container mt-5">
<h1>Blood Alcohol Content (BAC) Calculator</h1>
<form id="bacForm" class="mt-4">
<div class="form-group">
<label for="alcoholConsumed">Alcohol Consumed (oz):</label>
<input type="number" class="form-control" id="alcoholConsumed" required>
</div>
<div class="form-group">
<label for="bodyWeight">Body Weight (lbs):</label>
<input type="number" class="form-control" id="bodyWeight" required>
</div>
<div class="form-group">
<label for="gender">Gender:</label>
<select class="form-control" id="gender" required>
<option value="" disabled selected>Select your gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="form-group">
<label for="hours">Hours Since Drinking Began:</label>
<input type="number" class="form-control" id="hours" required>
</div>
<button type="button" class="btn btn-primary" onclick="calculateBAC()">Calculate BAC</button>
</form>
<h2 class="text-center mt-4" id="result"></h2>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions Calculators/Blood-Alcohol-Content-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function calculateBAC() {
const alcoholConsumed = parseFloat(document.getElementById('alcoholConsumed').value);
const bodyWeight = parseFloat(document.getElementById('bodyWeight').value);
const gender = document.getElementById('gender').value;
const hours = parseFloat(document.getElementById('hours').value);

if (isNaN(alcoholConsumed) || isNaN(bodyWeight) || isNaN(hours)) {
alert('Please enter valid numbers');
return;
}

let r;
if (gender === 'male') {
r = 0.73;
} else if (gender === 'female') {
r = 0.66;
} else {
alert('Please select a valid gender');
return;
}

const bac = (alcoholConsumed * 5.14 / bodyWeight * r) - (0.015 * hours);

document.getElementById('result').textContent = `Your BAC is ${bac.toFixed(4)}`;
}
25 changes: 25 additions & 0 deletions Calculators/Blood-Alcohol-Content-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
h1 {
text-align: center;
}

body,
html {
height: 100%;
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}

.bg {
background-image: url('https://tse2.mm.bing.net/th?id=OIP.fZRU5fmg6UCTdpJdb9BXkQAAAA&pid=Api&P=0&h=180');
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

.container {
background: rgba(255, 255, 255, 0.8);
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,20 @@ <h3>Given any number, it reaches to Four.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Blood Alcohol Content Calculator</h2>
<h3>Calculates the BAC based on the entered input values.</h3>
<div class="card-footer">
<a href="./Calculators/Blood-Alcohol-Content-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Blood-Alcohol-Content-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Blood Pressure Calculator</h2>
Expand Down