# Mental math booster.

One of the books I’m reading on my Kindle is Secrets of Mental Math: The Mathemagician’s Guide to Lightning Calculation and Amazing Math Tricks by renowned mathemagician Arthur Benjamin. The techniques he uses to do his astonishing mental calculations are amazingly simple and need only a little practice before you too can do math without a calculator. He reveals his secrets in this very fun book.

The book does include exercises to help me practice what I learned but after finishing them I was hungry for more numbers to crunch, so I decided to see what I could create using Javascript. I came up with the following script that serves the purpose perfectly.

<body>
<p id=”num1″>0</p>
<p id=”num2″>0</p>
<p id=”ans1″>Sum:</p>
<p id=”ans2″>Difference:</p>

<button onclick=”myFunction()”>Get Numbers</button>
<button onclick=”myFunction2()”>Calculate</button>

<script>
function myFunction()
{
var x=Math.floor(Math.random()*999);
var y=Math.floor(Math.random()*999);
document.getElementById(“num1”).innerHTML=x;
document.getElementById(“num2”).innerHTML=y;
document.getElementById(“ans1”).innerHTML=”Sum: “+ 0;
document.getElementById(“ans2”).innerHTML=”Difference: “+0;
a=x+y;
b=x-y;
}

function myFunction2(x,y)
{
document.getElementById(“ans1”).innerHTML=”Sum: “+ a;
document.getElementById(“ans2”).innerHTML=”Difference: “+b;
return a,b;
}
</script>
</body>

Running this script yields the following output:

When you click on “Get Numbers” you will see two randomly generated numbers for you to add and subtract in your head. When you think you have the answers figured out, click on “Calculate” to display the calculated sum and difference of the two numbers to see if you were right.

When I tested the script, I got the following two numbers to play with.

844
293

To mentally add these numbers, just break the process down to simpler steps. Instead of adding 293 as a whole, start by adding 200 to 844, which gives us 1044. Next we add 90 to get 1134 and finally we add 3 to get the sum of 1137.

Subtracting those two numbers is just as easy. Just round up 293 to 300 and subtract that from 844, which gives us 544. Then add the 7 you took away when you rounded up and you get 551, which is the answer.

This is really making math fun again. I still don’t know why it’s not taught like this at school.