JavaScript automatically generate equation for kids
My daughter is learning the arithmetic, I acquiesced in that she can use the calculator, but after 3 times testing, her manually calculating ability always lower the average level. A result is her math teacher talked with me for this issue. So I have to ask my daughter to exercise manually, but we have no existing equation, to be a programmer, I must not to design equation by myself. :-)
So I wrote some javascript code to generate equation, maybe it can help you guys for the same situation. The code is below, just copy&paste them into a HTML file, open in browse, pick the "generate equation" button, have fun!
<html>
<body>
<script type="text/javascript">
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function compute()
{
var signs=new Array();
signs[0]=" + ";
signs[1]=" - ";
signs[2]=" x ";
signs[3]=" ÷ ";
document.getElementById("p1").innerHTML=Math.random().toFixed(2)+ signs[getRandomInt(0,3)] +(100*Math.random()).toFixed(2)+ signs[getRandomInt(0,3)] +(10*Math.random()).toFixed(2);
}
</script>
<input type="button" value="Generate equation" style="font-size:60px;height:200px;width:600px" onclick=compute()>
<p style="font-size:80px;" id="p1"></p>
</body>
</html>
An issue is sometimes it will generate the negative equation likes below, if anyone have a good idea for this, please leave a message.