View Single Post
Old 04-04-2008, 14:45   #1 (permalink)
gilbs
Registered User
 
gilbs's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 8
If statement comparing a variable and input...

Hi I'm quite new to all this flash m'larky so forgive me if this seems a bit stupid...

I'm trying to make a basic game where two random numbers are generated and added together, then the user needs to put the answer into an input box in digits and check it. I'm just using "trace" to say whether the answer is right or wrong for the minute.

Im having problems with the check_btn part of the code. I'm trying to simply check if the user has put in the same number as the correct answer but every time it always traces "incorrect" whether it is or not.

I tried declaring userAnswer_txt as a variable and using that in the if statement but had the same problem...

Any ideas???

Code:
start_btn.onRelease = function () { var ran1=Math.ceil(Math.random()*9); var ran2=Math.ceil(Math.random()*9); num1_txt.text=ran1; num2_txt.text=ran2; var answer = ran1 + ran2; answer_txt.text = ran1 + ran2; }; check_btn.onRelease = function () { if (answer == userAnswer_txt){ trace ("correct"); } else{ trace ("incorrect"); } };

Thanks
  Reply With Quote