Code in choose frame


// Math Game

// Generates Random Math Problems

// Illustrates text fields, conditions

// basic math

// Andy Harris, 12/04



stop();



btnAdd.onRelease = function(){

  op = "+";

  _root.gotoAndStop("solve");

} // end add



btnSub.onRelease = function(){

  op = "-";

  _root.gotoAndStop("solve");

} // end sub



btnMult.onRelease = function(){

  op = "*";

  _root.gotoAndStop("solve");

} // end add



btnDiv.onRelease = function(){

  op = "/";

  _root.gotoAndStop("solve");

} // end add

Code in solve frame


btnCheck.onRelease = function(){

  _root.gotoAndStop("report");

} // end check release





//check operation

switch(op){

  case "+":

    X = Math.ceil(Math.random() * 10);

    Y = Math.ceil(Math.random() * 10);

    correct = X + Y;

    trace(correct);

  break;

  case "-":

    Y = Math.ceil(Math.random() * 10);

    correct = Math.ceil(Math.random() * 10);

    X = correct + Y;

    trace(correct);

  break;

  case "*":

    X = Math.ceil(Math.random() * 10);

    Y = Math.ceil(Math.random() * 10);

    correct = X * Y;

    trace(correct);

  break;

  case "/":

    Y = Math.ceil(Math.random() * 10);

    correct = Math.ceil(Math.random() * 10);

    X = correct * Y;

    trace(correct);

  break;

  default:

    trace("There's a problem here");

  break;

} // end switch

Code in report frame


btnBack.onRelease = function(){

  if (numTries < 5){

    //create another problem in the same set

    _root.gotoAndStop("solve");

  } else {

    //let user start over

    numRight = 0;

    numTries = 0;

    _root.gotoAndStop("choose");

  } // end if

} // end back release



//check to see if user is right

if (guess == correct){

  result = "Great Job!";

  numRight++;

} else {

  result =  X + " + " + Y + " = " + correct; 

} // end if



//update score

numTries++;

percRight = numRight/numTries * 100;