PHP Elementary Math and Functions In this assignment you need to create a web pa
ID: 3707067 • Letter: P
Question
PHP
Elementary Math and Functions
In this assignment you need to create a web page that generates a random math
problem math problem (addition only) in the format that an elementary school
student would understand (see image). The first two values (A and B) would be
randomly created and the user is expected to fill in a text field (for C) with the
answer and press a submit button, and then continue to see that page with an
appropriate response or a new problem. More information is given below, but I
want to see at least the following things in your code. Namely:
Explanation / Answer
<?php
if (isset($_GET["a"])) {$msg="Fb";$a=$_GET['a'];} else {$a="";}
if (isset($_GET["b"])) {$b=$_GET['b'];} else {$msg="a";$b="";}
if (isset($_GET["c"])) {$c=$_GET['c'];} else {$c="";}
if ($a=="") {
$a = rand(10,99); $b = rand(1,9); $c = "";
$msg="Fill in the blank to answer this math question.";
}
elseif (is_numeric($c) && $a+$b==$c) {
$a = rand(10,99); $b = rand(1,9); $c = "";
$msg="Correct! Now try this new problem.";
}
elseif (!is_numeric($c)) {
$c = "";
$msg= "You must enter a number and press the submit button.";
}
else {
$msg= "Incorrect! Please try again.";
}
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
input{
font-family: monospace;
font-size: 30pt;
font-weight: bold;
text-align: right;
}
form{
width: 100px;
}
</style>
</head>
<body>
<div>
<form action = "<?php $_PHP_SELF ?>" method = "GET">
<input type="text" outline="none" name="a" size="3" readonly value="<?php echo $a; ?>">
<br>
<input type="image" width="40" value="+">
<input type="text" name="b" size="1" readonly value="<?php echo $b; ?>">
<br>
<hr>
<input type="text" name="c" size="3"><br/>
<input type="submit" value="OK" name="but">
<br>
</form>
</div>
<h1><?php echo $msg; ?></h1>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.