The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Blood Alcohol Content Calculator code needed, need to adjust parameters on existing codes
http://www.bestbeerbuzz.com/
post Oct 9 2009, 01:10 PM
Post #1





Group: Members
Posts: 2
Joined: 9-October 09
Member No.: 9,988



Hi everyone,

I'm building a beer appreciation website and need help with a public code that I found on the web.

The code is for a blood alcohol content calculator and it currently reads the same message after 0.08. I'd like to offer different messages within more specific paramaters, such as 0.04 to 0.08, 0.08 to 0.12, 0.12 to 0.16, etc.

Ideally, in the future I'd like to be able to add multiple drink sources with different alcohol % values, but the parameters would be helpful for now.

I'd appreciate any help anyone can offer, thanks!

Chainsaw the Night
http://www.bestbeerbuzz.com/

<!-- TWO STEPS TO INSTALL BAC CALCULATOR:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<script LANGUAGE="JavaScript">
<!-- Original: James P. Dildine (jpd@wlsmail.com) -->
<!-- Web Site: http://www.mste.uiuc.edu/dildine -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function solveBAC(form) {
var ounces = eval(form.ounces.value);
var percent = eval(form.percent.value);
var weight = eval(form.weight.value);
var hours = eval(form.hours.value);

var result = (ounces * percent * 0.075 / weight) - (hours * 0.015);
if (result < 0) {
message = "There is a negligible amount of alcohol in your system. You are not legally intoxicated.";
result = "-- neglible amount --";
}
else {
if (result == "NaN")
mesage = "Please try again.";
if (result > 0.08)
message = "In MOST and possibly ALL states you would be considered intoxicated and arrested for DUI.";
if (result < 0.08)
message = "You are not legally intoxicated";
}
form.message.value = message;
form.bacamount.value = result + " %";
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>

<table>
<tr><td>
<ul>
<li>FLUID OUNCES CONSUMED<br>
(Beer ~ 12 oz. Wine Glass ~ 4 oz. 1 Shot ~ 1.5 oz)</li>
<li>YOUR WEIGHT (Lbs)</li>
<li>ALCOHOL PERCENTAGE IN BEVERAGE<br>
(Beer ~ 4-4.5% Wine ~ 15-20% 1 Shot ~ 30-50%)</li>
<li>HOURS CONSUMING DRINK</li>
</ul>
</td>
</tr>
</table>

<form method=post name=bacform>
<table border=4>
<tr>
<td align=center>
Fluid Ounces Consumed
</td>
<td align=center>
<input type=text name=ounces size=6>
</td>
<td align=center>
Percent Alcohol
</td>
<td align=center>
<input type=text name=percent size=6>
</td>
</tr>
<tr>
<td align=center>
Your Weight (Lbs)
</td>
<td align=center>
<input type=text name=weight size=6>
</td>
<td align=center>
Hours Consuming Drink
</td>
<td align=center>
<input type=text name=hours size=6>
</td>
</tr>
<tr>
<td colspan=4 align=center>
<input type=button name=bac value="Calculate Your BAC %" onClick="java script:solveBAC(this.form)">
</td>
</tr>
<tr>
<td align=center>
BAC Percentage
</td>
<td colspan=3 align=center>
<input type=text name=bacamount size=21>
</td>
</tr>
<tr>
<td align=center>
BAC Analysis
</td>
<td colspan=3 align=center>
<textarea name=message rows=3 cols=35 wrap=virtual></textarea>
</td>
</tr>
</table>
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 2.67 KB -->
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Oct 9 2009, 02:27 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,731
Joined: 9-August 06
Member No.: 6



You need to change this bit
CODE
if (result > 0.08)
message = "In MOST and possibly ALL states you would be considered intoxicated and arrested for DUI.";
if (result < 0.08)
message = "You are not legally intoxicated";


to a series of tests like this.
CODE
if ((result > 6 )&&( result < 8 ))
message ="some blah bla";


Also, it's more common to use 'else if' than just a series of 'if'.

CODE
if (some condition)
  {
    // do someting
  }
else if (another condition)
  {
    //do something
  }
else if (yet another condition)
  {
    //do something
  }
else  (last condition)
  {
    //do something
  }
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
http://www.bestbeerbuzz.com/
post Oct 14 2009, 10:58 AM
Post #3





Group: Members
Posts: 2
Joined: 9-October 09
Member No.: 9,988



Thanks for the help, pandy!

With some tweaking and patience, I got exactly what I needed from your more common "else if" suggestion.

Take a look at the result: http://www.bestbeerbuzz.com/BAC-Calculator.html

Thanks again!

http://www.bestbeerbuzz.com/index.html

Chainsaw the Night!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Oct 14 2009, 11:44 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,731
Joined: 9-August 06
Member No.: 6



It says I'm pleasantly pissed. tongue.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 26th April 2024 - 01:12 PM