• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Formula gives NaN as answer

New Here ,
May 27, 2012 May 27, 2012

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);

TOPICS
ActionScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

what is assigned value for genderconstant

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2012 May 28, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2012 May 28, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2012 May 28, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 28, 2012 May 28, 2012

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)

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2012 May 29, 2012

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;?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 30, 2012 May 30, 2012

Copy link to clipboard

Copied

LATEST

Obviously this is not the full codgo, is not the definition of any variabla with the exception of BAC1.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines