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>...

  • Im working with php but having problem displaying the correct result. I need to show Order...

    Im working with php but having problem displaying the correct result. I need to show Order processed at (time) HTML file: <!DOCTYPE html> <html> <head> <title>Bob's Auto Parts - Order Form</title> </head> <body> <form action="processorder.php" method="post"> <table style="border: 0px;"> <tr style="background: #cccccc;"> <td style="width: 150px; text-align: center;">Item</td> <td style="width: 15px; text-align: center;">Quantity</td> </tr> <tr> <td>Tires</td> <td><input type="text" name="tireqty" size="3" maxlength="3" /></td> </tr> <tr> <td>Oil</td> <td><input type="text" name="oilqty" size="3" maxlength="3" /></td> </tr> <tr> <td>Spark Plugs</td> <td><input type="text" name="sparkqty" size="3" maxlength="3" /></td>...

  • 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...

  • 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:...

  • 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) {...

  • Write a PHP Script containing a function that calculates the tax (8%) on a purchase of...

    Write a PHP Script containing a function that calculates the tax (8%) on a purchase of $48.72. What I have so far. index.html <!DOCTYPE html> <html lang="en"> <head> <title>PHP Lab II</title> <meta charset="utf-8"> <link rel="stylesheet" href="main.css"> <meta name="robots" content="noindex, no follow, noarchive" /> <meta name="author" content="Michael Dimond Jr" /> </head> <body> <div id="wrapper"> <header> <h1>PHP Lab II</h1> </header> <main> <form action="display.php" method="post">    <div>        <label>Sale Total: </label>        <input type="text" name="sale_total"><br>        <br>    </div>   ...

  • I have created an HTML form. I need to connect this to a database to update...

    I have created an HTML form. I need to connect this to a database to update the phone number in the employee table HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> </head> <body link="#0000EE" vlink="#551A8B" text="#000000" bgcolor="#566573" alink="#EE0000" background="../DOC/brushed-alum.png"> <form method="post" action="phonenumbers.php"> <h1>Update Employee Phone Number Form</h1> <br> <br> <h3>Enter the employee's ID number.</h3> <br> <br> Employee ID Number: <input name="EmployeeNumber" type="text"> <br> <br> <h3>Enter the new phone number</h3> Phone Number: <input name="OfficePhone" type="text">...

  • 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,...

  • PHP Programming with MySQL - Why do I get the following error and how do I...

    PHP Programming with MySQL - Why do I get the following error and how do I connect to my database. Looks like I might need to use mysqli instead of mysql but I dont know how to do that or what to change. I appreciate it is you fixed anything that needs to be re-written. Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php:12 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 12 Line 12: $DBConnect =...

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