                                



                       
                        function chooseanumber (limit)
                        {
                         /*choose a random number between 0 and limit-1. limit less than 100000*/
                           y=Math.random();
                           y=Math.round(y*100000);
                           z=Math.floor(y/limit);
                           x=y-(z*limit)
                         }

                        

                        function checkanswer (type)
                         {
                         if (type=="+") 
                               {answer=document.add.answer.value;
                                youranswer=document.add.myanswer.value};
                         if (type=="-") 
                             {answer=document.sub.answer.value;
                              youranswer=document.sub.myanswer.value};
                         if (type=="x") 
                             {answer=document.mult.answer.value;
                              youranswer=document.mult.myanswer.value};
                         if (type=="/") 
                             {answer=document.div.answer.value;
                              youranswer=document.div.myanswer.value};
                         correctmessage="Your answer is correct!";
                         errormessage="Sorry, your answer was incorrect.\nEither try again, or press the 'show me the answer' button located directly below this box.";
                         nomessage="Sorry, you have to try to solve this problem before pressing this button";
                         if (youranswer=="")
                            {if (type=="+") {document.add.messagebox.value=nomessage};
                             if (type=="-") {document.sub.messagebox.value=nomessage};
                             if (type=="x") {document.mult.messagebox.value=nomessage};
                             if (type=="/") {document.div.messagebox.value=nomessage}}
                         else if (youranswer==answer)
                            {if (type=="+") {document.add.messagebox.value=correctmessage};
                             if (type=="-") {document.sub.messagebox.value=correctmessage};
                             if (type=="x") {document.mult.messagebox.value=correctmessage};
                             if (type=="/") {document.div.messagebox.value=correctmessage}}
                          else
                             {if (type=="+") {document.add.messagebox.value=errormessage};
                             if (type=="-") {document.sub.messagebox.value=errormessage};
                             if (type=="x") {document.mult.messagebox.value=errormessage};
                             if (type=="/") {document.div.messagebox.value=errormessage}}
                         }


                                      

     
                       function remarks (type)
                       {
                         if (type=="+") 
                               {youranswer=document.add.myanswer.value;
                                message=document.add.message.value};
                         if (type=="-") 
                               {youranswer=document.sub.myanswer.value;
                                message=document.sub.message.value};
                         if (type=="x") 
                               {message=document.mult.message.value;
                                youranswer=document.mult.myanswer.value};
                         if (type=="/") 
                             {message=document.div.message.value;
                              youranswer=document.div.myanswer.value};
                        

                         errormessage="Sorry, you have to try to solve this problem before requesting the solution";
                         if (youranswer=="")
                            {if (type=="+") {document.add.messagebox.value=errormessage};
                             if (type=="-") {document.sub.messagebox.value=errormessage};
                             if (type=="x") {document.mult.messagebox.value=errormessage};
                             if (type=="/") {document.div.messagebox.value=errormessage}}
                         else
                             {if (type=="+") {document.add.messagebox.value=message};
                             if (type=="-") {document.sub.messagebox.value=message};
                             if (type=="x") {document.mult.messagebox.value=message};
                             if (type=="/") {document.div.messagebox.value=message}}
                         }
                                                 

                   



                      function genmult()
                  {
                   chooseanumber(10);
                   a=x+1;
                   chooseanumber(10);
                   b=x+1;
                   answer=a*b;
                   problem=a+' x '+b;
                   document.mult.problem.value=problem;
                   document.mult.answer.value=answer;
                   document.mult.message.value=problem+' = '+answer
                  }
                   
                  function gendiv()
                  {
                   chooseanumber(10);
                   a=x+1;
                   chooseanumber(10);
                   b=x+1;
                   c=a*b;
                   problem=c+' divided by '+b;
                   document.div.problem.value=problem;
                   document.div.answer.value=a;
                   document.div.message.value=problem+' = '+a
                  }

                   
                  function genadd()
                  {
                   chooseanumber(10);
                   a=x+1;
                   chooseanumber(10);
                   b=x+1;
                   answer=a+b;
                   problem=a+' + '+b;
                   document.add.problem.value=problem;
                   document.add.answer.value=answer;
                   document.add.message.value=problem+' = '+answer
                  }

                  function gensub()
                  {
                   chooseanumber(10);
                   a=x+1;
                   chooseanumber(10);
                   b=x+1;
                   if (a>=b)
                      {problem=a+' - '+b;
                       answer=a-b}
                   else
                       {problem=b+' - '+a;
                        answer=b-a};
                   document.sub.problem.value=problem;
                   document.sub.answer.value=answer;
                   document.sub.message.value=problem+' = '+answer
                  }

