Make your own free website on Tripod.com
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
  
  <HEAD>
    <TITLE>
      Test Your Multiplication Power!
    </TITLE>
    <META name="GENERATOR" content="Arachnophilia 4.0">
    <META name="FORMATTER" content="Arachnophilia 4.0">
    
<SCRIPT LANGUAGE = "JavaScript">

function question()
{
  var num1, num2;
  num1 = Math.floor( 1 + Math.random() * 9 );
  num2 = Math.floor( 1 + Math.random() * 9 );
  document.forms["multiply"].Q.value = "How much is "+num1+" times "+num2+"?";
  document.forms["multiply"].answer.value =  num1 * num2 ;
  document.forms["multiply"].guess.value = "";
  document.forms["multiply"].guess.focus();
}

function checkAns()
{
  var msg;
  if (document.forms["multiply"].answer.value == document.forms["multiply"].guess.value)
  {
  switch (Math.floor( 1 + Math.random() * 4 )){
     case 1 :
      msg = "Very good!";
        break;
     case 2 :
      msg = "Excellent!";
        break;
     case 3 :
      msg = "Nice Work!";
        break;
     case 4 :
      msg = "Keep up the good work!";
        break;
     default :
    msg = "Very good!";
  }
window.status = msg;
    question();
  }
  else {
  switch (Math.floor( 1 + Math.random() * 4 )){
   case 1 :
    msg = "No.  Please try again.";
      break;
   case 2 :
    msg = "Wrong.  Try once more.";
      break;
   case 3 :
    msg = "Don't give up.";
      break;
   case 4 :
    msg = "No.  Keep trying.";
      break;
   default :
msg ="No.  Please try again.";
}
    window.status=msg;
    document.forms["multiply"].guess.select();
    document.forms["multiply"].guess.focus();
  }
}

</SCRIPT>
    
  </HEAD>

  <BODY ONLOAD="question()">

    Exercise 11.30
    <P>    
    <CENTER>
      <H2>
        Test Your Multiplication Power!
      </H2>
    </CENTER>
    <FORM NAME = "multiply">
      <INPUT type="hidden" name="answer" value=0>
      <TABLE BORDER = "0" align="center">
        <TR>
          <TD>
            <INPUT type="text" name="Q" size="30"  value="default value">
          </TD>
        </TR>
        <TR>
          <TD>
            Enter answer here: 
            <INPUT TYPE = "text" NAME = "guess" size="4" maxlength="3" value="0">
             
            <INPUT type="button" value="Am I right?" onclick="checkAns()">
          </TD>
        </TR>
        <TR>
        </TR>
        <TR>
          <TD align=center>
            <FONT size="-1">
              <I>
                See answer in status bar below
              </I>
            </FONT>
          </TD>
        </TR>
      </TABLE>
    </FORM>
    <a href="11_30src.html">View Source</a>
  </BODY>
</HTML>