I just created a couple of PHP scripts for my nephew to help him with his math. Actually, any kid or adult can use it. The program performs some basic mathematics such as addition, subtraction, multiplication and division. The numbers and result are totally random. You will get a different set of numbers and result each time. You can play with it as long as you want, and as often as you like.

The result of each equation is hidden when the page is initially loaded. You can click the “Display Answer” link to reveal the answer. Clicking the “New Question” link will generate a different set of random numbers. Navigation is located at the top. You can select: Addition, Subtraction, Multiplication and Division. Give it a try.

Just a couple of other things that I wanted to mention. I’m using Javascript to hide the answers when the documents are initially loaded. The math result is contained inside a hidden div. The div is toggled on or off or displayed or hidden, by simply clicking on a link. The Javascript that I use can be viewed and copied if you look at the source.

In addition, I’m using simple a rand() function to generate a set of numbers. I use basic PHP math operations to perform the math operations. I do a couple of checks in subtraction and division scripts to avoid the following: subtraction which results in negative number, division by zero, and a divisible number, meaning no remainders when performing divisions. The scripts can be easily modified.

### Examples

#### Addition

$a = rand(0, 20); // This generates a random number between 0 and 20. $b = rand(0, 20); // This generates a random number between 0 and 20. $c = $a + $b; // Performs addition |

#### Subtraction

$a = rand(0, 20); // This generates a random number between 0 and 20. $b = rand(0, 20); // This generates a random number between 0 and 20. if ($a>$b) {$c=$a-$b;} else {$c=$b-$a;} // No negative results |

#### Division

$a = rand(2, 100); // This generates a random number between 2 and 100. $b = rand(2, 100); // This generates a random number between 2 and 100. do { $c = $a / $b; } while ($a % $b != 0) // Checks if result is divisible |

It was a fun little project.