-
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?
-
Senior Member
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
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|