Question

PHP, HTML

I have this code in the picture below for a guess game.

<!DOCTYPE html> <!-- guess.php --> <html> <head> <title>Guess a Number</title> </head> <?php POST) { if ($_SERVER[REQUEST_

I need help modifying and improving it.

1. Add HTML file including contents to make the page feel more complete.

2. Add CSS file

3. overall Improve the gaming aspects, such as setting a flag that shows the correct number, allowing multiple tries

4. Make the (end-of-game) message more friendly

this is the code in the picture so it can be copied easily:

<!DOCTYPE html> <!-- guess.php -->
<html>
<head>
<title>Guess a Number</title>
</head>
<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$randNum = rand(1, 10);
  
if ($randNum == $_POST["num"]) {
echo "<h1>Correct!</h1>";
}
else {
echo "<p>No, I was thinking of $randNum.</p>";
}
}
?>
  
<form method="post" action="guess.php">
<p>I'm thinking of a number between 1 and 10.</p>
<p>Your guess? <input type="number" name="num" min="1" max="10" autofocus></p>
<input type="submit" value="Guess">
</form>
</html>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I've made few changes in your code as per your suggestion:

index.php

<!DOCTYPE html> <!-- guess.php -->
<html>
<head>
<title>Guess a Number</title>
</head>
<style>
body{
    background-color:orange;
}
form{
margin-left:100px;
margin-top:100px;
color:indigo;
font-size:22px;
}
input[type="submit"]{
background-color:indigo;
padding:5px;
width:60px;
font-size:14px;
height:30px;
color:white;
}
</style>
<body>

<form method="post" action="guess.php">
<p>I'm thinking of a number between 1 and 10.</p>
<p>Your guess? <input type="number" name="num" min="1" max="10" autofocus></p>
<input type="submit" value="Guess">
</form>

</body>

</html>

guess.php

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$randNum = rand(1, 10);
  
if ($randNum == $_POST["num"]) {
echo "<h1>Correct!</h1>";
}
else {
echo "<p>No, I was thinking of $randNum.</p>";
}
}
?>
<html>
<head>
<style>
body{
    background-color:orange;
}
#myButton{
background-color:indigo;
padding:5px;
width:60px;
font-size:14px;
height:30px;
color:white;
}
</style>
</head>
<body>
<button id="myButton" class="float-left submit-button" >Home</button>

<script type="text/javascript">
    document.getElementById("myButton").onclick = function () {
        location.href = "http://localhost/index.php";
    };
</script>
</body>
</html>  

Screenshots that can help you.

Im thinking of a number between 1 and 10. Your guess? Guess

No, I was thinking of 8. Home

Add a comment
Know the answer?
Add Answer to:
PHP, HTML I have this code in the picture below for a guess game.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head>...

    PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head> <script> </script> </head> <body> <h2>Temperature Conversion Table</h2> <h4>Enter a starting value in degrees Fahrenheit and an increment value.</h4> <form name="myTemp" onsubmit="convertCelcius()" method="post"> <input type="text" name="temperature"> Enter an value in degrees Fahrenheit<br><br> <input type="radio" name="degIncrement" id="degIncrement5"> Convert in increment in 5 degrees<br> <input type="radio" name="degIncrement" id="degIncrement10"> Convert in increment in 10 degrees <br/><br/><input type="submit" value="Submit"> </form> <?php if( $_POST["temperature"] || $_POST["degincrement"] ) { //get he...

  • Create a PHP-backed webpage that ask for a number and calculate is square 10 times. Hint...

    Create a PHP-backed webpage that ask for a number and calculate is square 10 times. Hint 1: <html> <body> <h1>Iteration Program</h1> Today's date: <?php echo date("1 F d, Y"); ?> <h3>Enter a Value to Iterate</h3> <form action="results.php",method=post> <input type="text" name="data"> <p/> <input type="submit" value="Show Results"> </form> </body> </html> Hint 2: <html> <body> <h1>Iteration Results</h1> <b>Here are 10 iterations of the formula:<br/> y=x<sup>2</sup> </b> <p/> <!-- PHP Calculations start here! --> <?php $num = $_POST['data']; //Write your code Here! ?> </body>...

  • PHP code that is given : <?php // Here is where your preprocessing code goes //...

    PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...

  • PHP - Use of classes This is a further development of the previous task, the participant...

    PHP - Use of classes This is a further development of the previous task, the participant registration. You must use the following Participant class. <?php class Deltaker { private $etterNavn; private $forNavn; private $fAar; function __construct(string $fornavn, string $etternavn, string $aar) { $this->forNavn = $fornavn; $this->etterNavn = $etternavn; $this->fAar = $aar; } function hentEtterNavn() : string { return $this->etterNavn; } function hentForNavn() : string { return $this->forNavn; } function hentFAar() : string{ return $this->fAar; } //Setters function settForNavn(string $fornavn) {...

  • LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...

    LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES login.html <!DOCTYPE html> <html> <head> <title>login popup</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> body { background-color: white; } </style> </head> <body> <center> <h1 style="text-align: center;"> Login </h1> <form>             Login ID:...

  • Hey Guys I am doing a project and need some help with code in HTML and...

    Hey Guys I am doing a project and need some help with code in HTML and PHP. I need a form made in HTML that can be sent to a specific email through PHP. For some reason the info is not getting sent to my email, even though it says that it was sent. I have some source code here: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $email = mail('MY_EMAIL', $subject, $message,...

  • I am having an issue. When i press submit to test the code, it goes to...

    I am having an issue. When i press submit to test the code, it goes to a blank screen. Please, will some one assist me? Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Sign Guest Book</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php if (empty($_POST['?rst_name']) || empty($_POST['last_name']))     echo "<p>You must enter your ?rst and last name! Click your browser's Back button to return to the Guest Book form.</p>"; else {     $DBConnect = @mysql_connect("localhost", "root", "");    ...

  • How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow...

    How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...

  • Hello, I was wondering if someone could help me with this PHP and HTML problem. Basically,...

    Hello, I was wondering if someone could help me with this PHP and HTML problem. Basically, there is code for a multiplication table and i need to change it to support the following. Make the page background (not table background) to change among three colors of your choice. Use the drop-down list to specify the size of the multiplication table to be 8, 10, 12, and 14 Put the multipliers in the first column and the multiplicand on the first...

  • Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php...

    Q1. rewrite the exercise on April 4 by adding the following operations: 1) In the php script, create an associative array named $order that stores the following values: - the number of cheese toppings; - the number of pepperoni toppings; - the number of ham toppings; - the size of the ordered pizza; - the number of the ordered pizza; - the total cost of the order; - the discount rate; - the total cost after the discount. 2) the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT