Copy link to clipboard
Copied
num and genderconstant are working as integers, but the formula isn't working. I defined var drinks = 0; and var hours = 0; on another page. Any thoughts as to why this code isn't working?
import flash.events.MouseEvent;
mornshots_btn.addEventListener(MouseEvent.CLICK, takeShots);
function takeShots(event:MouseEvent):void
{
drinks++;
trace(drinks);
mornshots.text = String(drinks);
}
hours = hours+4;
var BAC1 = (drinks * 0.06 * 100 * 1.055 / num * genderconstant - 0.015 * hours);
q1_btn.addEventListener(MouseEvent.CLICK, traceBAC1);
function traceBAC1(event:MouseEvent):void
{
trace(BAC1)
}
mornshots.text = String(drinks);
Copy link to clipboard
Copied
what is assigned value for genderconstant
Copy link to clipboard
Copied
Try tracing each of the variables in that line to see which one(s) are not numerically defined. If any happen to come from textfields, then you need to be sure to convert the values from text to numbers before trying to process them.
Also, unless there are other circumstance around that code, that line of code you show in red will only execute once at the beginning of testing since it is not inside any function. So whatever value you trace for it will not change even if values that would define it change later on.
Copy link to clipboard
Copied
All of the variables are working, but now the answer is always -.06, no matter what the weight input is (num = weight).
The formula I have is BAC1 =((drinks * 0.06 * 100 * (1.055/num) * genderconstant) - (0.015 * hours));
It's different than the original, but there's still the same problem.
Gender constant depends on the person's gender. .66 for female and .73 for male.
Copy link to clipboard
Copied
What are the values of all the variables when the program starts? If you expect it to be anything else than whatever that value is (I'd guess it eautes to -.06), then you probably want to reread the second paragraph of my first response.
Copy link to clipboard
Copied
Maybe you need
function calculate():void{
trace('drinks: '+drinks);
trace('num: '+num);
trace('genderconstant: '+genderconstant);
trace('hours: '+hours);
total =(drinks * 0.06 * 100 * 1.055 / num * genderconstant) - (0.015 * hours)
}
Copy link to clipboard
Copied
As far as I can tell hours hasn't been assigned as a variable. Did you mean var hours:int = 4;?
Copy link to clipboard
Copied
Obviously this is not the full codgo, is not the definition of any variabla with the exception of BAC1.