A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: maths quiz...

  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    33

    maths quiz...

    hmm..i dun know if this is the right board to post cos my question is very simple..

    i am creating a maths quiz...

    There are 2 input text fields..The instance names of 2 input text fields are inputField and inputField02.

    There is one dynamic text field to display the result....The instance name of dynamic text field is resultField.

    Code:
    var a: Number;
    var b: Number;
    
    a=inputField.text;
    b=inputField02.text;
    
    
    answer_btn.onRelease = function() {
    resultField.text = a/b;
    }
    however when i press on answer button, the result displayed is NaN.

    What's wrong with the code?

  2. #2
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    You are trying to run a Math operation on strings and thats why you are getting the result as not-a-number (NaN). You need to modify one line of code:

    PHP Code:
    resultField.text Number(a)/Number(b); 
    This should work. This process is called as type casting and ideally this should be avoided. Type casting is never a good practice as it has a very high probablity of inducing bugs in your programming logic. But for now, you may use it.
    Last edited by vinayak.kadam; 08-07-2009 at 05:48 AM. Reason: explained type casting!
    As ever,
    Vinayak Kadam

  3. #3
    Banned
    Join Date
    Jun 2022
    Posts
    1
    Thanks for post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center