-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Blood Alcohol Content Calculator (#1372)
- Loading branch information
1 parent
a92bcc0
commit c110008
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters