Skip navigation
hhafke10
Currently Being Moderated

Formula gives NaN as answer

May 27, 2012 7:58 PM

Tags: #calculator

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

 
Replies
  • Currently Being Moderated
    May 28, 2012 12:12 AM   in reply to hhafke10

    what is assigned value for genderconstant

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 4:31 AM   in reply to hhafke10

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 1:43 PM   in reply to hhafke10

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 1:56 PM   in reply to hhafke10

    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)

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 9:47 PM   in reply to esdebon

    As far as I can tell hours hasn't been assigned as a variable. Did you mean var hours:int = 4;?

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 7:47 AM   in reply to I_am_the_real_Z

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points