Question
PHP Need help here. Create a web page that generates a random math problem math problem (addition only) in the format that an elementary school
PHP
Need help here.
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. I want to see at least the following things in your code. Namely:
Use functions like is_numeric and rand
Important: Define one or more of your own functions and use it.
First, you will want large monospaced fonts for you numbers that are right aligned in the areas you place them so that the digits line up. I suggest you create a style class and use it in the numbered text and the text field something like the style below:
The other thing that will be helpful is to understand what all the different STATES are so that you can cover each one of them. As I see it the 4 STATES are as follows: 1. No variables passed to it. For this display a new problem 2. The answer is correct (e.g. A + B = C). Congratulate the user and move to a new problem. 3. The answer is still empty or non-numeric. Keep the problem there but dont say it is wrong. 4. The numeric answer is incorrect. Keep the problem and the answer with a try again message
if (isset($_GET['a'])) {$a=$_GET['a'];} else {$a="";} if (isset($_GET['b'])) {$b=$_GET['b'];} else {$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."; } Following this you would generate the form based on the values you set above. Thus, if $a, $b, and $c have new values then the user will see different values. If $c was set to the empty string then the text field will appear empty.
What it should look like:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started