What is 10 X 9
Answer: 90
<?php
$divisionArray = array();
$type = $_GET['type'];
if (empty($type))
{
$type = 'multiplication';
}
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=macintosh">
<title>'.ucfirst($type).'</title>
</head>
<body>';
switch($type)
{
case 'multiplication':
$numbers = array(1=>1,2,3,4,5,6,7,8,9,10,11,12);
$a = array_rand($numbers,1);
$b = array_rand($numbers,1);
$question = "<div>What is $a X $b</div>";
$answer =$a * $b;
break;
case 'division':
$maxNumber = 144;
//$divisionArray = array(1=>1);
$finalArray = array();
for($i = 1; $i <= $maxNumber; $i++)
{
$divisionArray[] = $i;
}
foreach($divisionArray as $list)
{
for($i = 2; $i <=12; $i++)
{
if (($list % $i) <= 0)
{
if ($list != $i)
{
$finalArray[$list] = $i;
}
}
}
}
$a = array_rand($finalArray, 1);
$b = $finalArray[$a];
$question = "<div>What is $a / $b</div>";
$answer = $a / $b;
break;
default:
$question = "<div>An error occured. Please click on a link below.</div>";
break;
}
echo $question;
?>
<div style=" border: 1px solid #000; padding: 30px; width: 60px;">
Answer: <span id="answer" style="display: none;"><?php echo $answer; ?></span>
</div>
<br>
<div><button onClick="showAnswer();">Show/Hide Answer</button></div>
<div><a href="index.php?type=multiplication" target="_self">Ask me Another multiplication question</a></div>
<div><a href="index.php?type=division" target="_self">Ask me Another division question</a></div>
<script language="javascript" type="text/javascript">
function showAnswer()
{
var status = document.getElementById('answer').style.display;
if (status == 'none')
{
document.getElementById('answer').style.display = 'block';
}
else
{
document.getElementById('answer').style.display = 'none';
}
}
function showCode()
{
var status = document.getElementById('code').style.display;
if (status == 'none')
{
document.getElementById('code').style.display = 'block';
}
else
{
document.getElementById('code').style.display = 'none';
}
}
</script>
<?php
echo '<div><a href="javascript: void(0);" onclick="showCode();">Show the PHP code to make this work</a></div>';
echo '<div id="code" style="display: none;">'.highlight_file('index.php', TRUE).'</div>';
?>
</body>
</html>