»
EnglishFrenchVietnamese

Print - Math Quiz - JavaScriptBank.com

Full version: jsB@nk » Game » Math Quiz
URL: https://www.javascriptbank.com/math-quiz.html

Math Quiz © JavaScriptBank.comFlash cards were pretty good math practice. But, they were always the same math problems, over and over. Lo and behold, JavaScript to the rescue! Just select the difficulty level then click the type of problem you want to practice with, (add, subtract, multiply, and divide) and JavaScript will give you a problem. And, a built-in score checker grades you along the way!Great practice for elementary-aged students just learning their math skills, or for anyone wishing to practice a bit!

Full version: jsB@nk » Game » Math Quiz
URL: https://www.javascriptbank.com/math-quiz.html



JavaScript
<SCRIPT LANGUAGE="JavaScript"><!-- Begin<!--START OF TIMER SCRIPT-->//how much time they getvar time=45;var timesup=0;var started=0;function CountDown() {if(time>0){document.math.timer.value=time;time=time-1;var gameTimer=setTimeout("CountDown()", 1000)}else if (time==0){document.math.timer.value="0";timesup=1;alert('Time\'s Up!');document.math.firstnum.value="";document.math.operator.value="";document.math.secondnum.value="";document.math.answer.value="";}}<!--END OF TIMER SCRIPT-->function startgame(){if (started!=0){alert('You\'ve Already Started!');}else{started=1;CountDown();getProb();}}<!--START OF RANDOM NUMBER SCRIPT-->function randnum(min,max){var num=Math.round(Math.random()*(max-min))+min;return num;}<!--END OF RANDOM NUMBER SCRIPT-->var choose, rightanswerfunction getProb(){choose=randnum(1,4);if (choose=="1"){document.math.operator.value="+";var choose1=randnum(0,50);var choose2=randnum(0,50);document.math.firstnum.value=choose1;document.math.secondnum.value=choose2;rightanswer=choose1 + choose2;}if (choose=="2"){document.math.operator.value="-";var choose2=randnum(0,50);var choose1=randnum(choose2,50);document.math.firstnum.value=choose1;document.math.secondnum.value=choose2;rightanswer=choose1 -  choose2;}if (choose=="3"){document.math.operator.value="x";var choose1=randnum(0,10);var choose2=randnum(0,10);document.math.firstnum.value=choose1;document.math.secondnum.value=choose2;rightanswer=choose1 * choose2;}if (choose=="4"){document.math.operator.value="/";var choose2=randnum(1,10);var choose1=choose2 * randnum(0,10);document.math.firstnum.value=choose1;document.math.secondnum.value=choose2;rightanswer=choose1 /  choose2;}}function answerit(){if (started==0){alert('You Must Click The Button Labeled \'Start\'!');}else{if (timesup!=0){alert('Time Ran Out!');}else{var theiranswer=eval(document.math.answer.value);var theirpoints=eval(document.math.points.value);if (theiranswer==null){alert('Put Your Answer In The Box To The Left Of The Button Labeled \'Dap an\'!');document.math.answer.select();}else{if (theiranswer==rightanswer){alert('Right');theirpoints++;document.math.points.value=theirpoints;}else{alert(theiranswer + " is wrong!\n\n"+rightanswer + " is correct!")}document.math.answer.select();getProb();}}}}//  End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<table align="center">  <tr>    <td colspan="3" align="center"><input type="button" value="New Game" onClick="location.reload();"></td></tr><tr>    <td colspan="3" align="center"><input type="button" value="Start" size="5" onClick="startgame()"></td>  </tr>  <tr>    <form name="math">      <td colspan="3" align="center"><b><font size="3" color="#0000FF">Time: </font></b> <font size="3" color="#0000FF"> </font><input type="text" name="timer" size="5"></td>    </tr>    <tr>      <td align="right"><b><font size="3" color="#0000FF">Question: </font></b> <font size="3" color="#0000FF"> </font><input type="text" name="firstnum" size="5"></td>      <td align="center"><input type="text" name="operator" size="2"></td>      <td align="left"><input type="text" name="secondnum" size="5"></td>    </tr>    <tr>      <td colspan="3" align="center"><hr><b><font size="3" color="#0000FF">Result:</font> </b> <input type="text" name="answer" size="5"> <input type="button" value="Answer" onClick="answerit();"><hr></td>    </tr>    <tr>      <td  colspan="3" align="center"><font color="#0000FF">Corrects</font><font face="Arial, Helvetica, Sans Serif" size="3" color="#0000FF"><b>:</b> </font> <input type="text" name="points" size="5" value="0"></td>    </tr>    <tr>    </form>  </tr></table><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->