Hello,
I have a simple math game where the user enters his answer and clicks a button. The problem I am having is that if the answer is wrong, the numbers in the question do not change on the screen but but in the actionscript, the variables being used to check the answer change. How do I get the variables to stay the same when the user’s answer is wrong? Not redeclare all of the variables.
var num1:uint = Math.Random()*1000;
var num2:uint = Math.Random()*1000;
var sum1:uint = num1 + num2;
top_num.text = num1.toString();//write to textfield.
bott_num.text = num2.toString();
enter_btn.addEventListener(MouseEvent.MOUSE_UP, checkAnswer);
function checkAnswer(e:MouseEvent):void
{
var sum_in1:Number = Number(sum_in.text);//user input.
if(sum_in1 == sum1)
{
var num1:uint = Math.random() * 1000;
var num2:uint = Math.random() * 1000;
top_num.text = num1.toString();//write to textfield.
bott_num.text = num2.toString();
}
else
{
//incorrect message here.
}
}