PHP Random Number Game Project

I need to make a game that follows these guidelines…

The computer chooses a random number from 0-10 (0 and 10 included). Using a radio button interface, the user should decide if the next number will be larger or smaller than the one shown. After the user submits their first answer, a new element should appear at the top indicating the conclusion of the game the user just played.

if the two random numbers match, the computer gets a point. If the user guesses correctly, the user gets a point. If the user guesses incorrectly, the computer gets a point.

Every 5 rounds the game should ask the user to guess the next number exactly. If the user guesses correctly they get 5 points. If they guess incorrectly the computer gets one point.

That’s easy enough… What code have you created so far?
This sounds a little like a class project. If so, I can give you some starting info, but, you need to code the
page to work it all out. We can help with your errors…

You would need to create the HTML page first with the radio buttons in place.
You would need to create some PHP code to create the random numbers and to keep track of the various
parts of the page. ( Such as the current number and the radio button value selected and the round number
and of course the score. )

Once you get it working or have errors, post your code inside the PHP tags above the area you type in so we
can see how you worked it out. Good luck!

Just to give you a little more info to help you along, in addition to what [member=43746]ErnieAlex[/member] has provided, which is excellent advice.

You’re going to be using the rand function, which you can learn more about here…

http://php.net/manual/en/function.rand.php

For you to generate the random number between 0 and 10, it will be this statement:

[php]$ranNo = rand(0, 10);
echo $ranNo;[/php]

This basically stores the randomly generated number in a variable called $ranNo and then displays it using the “echo” command.

Sounds like a fun project. Let us know, if you get stuck.

Sponsor our Newsletter | Privacy Policy | Terms of Service