Login Register






Guess random number filter_list
Author
Message
RE: Guess random number #9
Here's my final code i'll be glad to get comments if there's anything i should fix in my code.
Spoiler:
Code:
<?php session_start(); if(isset($_SESSION["hasStarted"])==false){ $_SESSION["number"]=rand(0,100); $_SESSION["hasStarted"]=true; $_SESSION["tries"]=0; } ?> <html> <head> </head> <body> <div><p>Guess the hidden number between 0 and 100</p> <form method="post" action="random.php"> <input type="text" name="number"/> <input type="submit" value="Guess"/> </form></div> <?php if($_POST){ $_SESSION["tries"]++; if($_POST["number"]==$_SESSION["number"]){ $_SESSION["hasStarted"]=false; ?><script>alert("You've guessed the hidden number after "+<?php echo $_SESSION["tries"];?>+" tries");</script> <div><a href="random.php">PLAY AGAIN</a></div> <?php unset($_SESSION["hasStarted"])?> <?php $_SESSION["tries"]=0; } else{?> <script><?php if($_SESSION["number"]<$_POST["number"]){?>alert("Hidden number is smaller");<?php }?></script> <script><?php if($_SESSION["number"]>$_POST["number"]){?>alert("Hidden number is bigger");<?php } ?></script> <?php }} ?> </body> </html>


Everyone should learn how to code, it teaches you how to think.

You don't have to be a Genius to know how to code you just need to be determined.

The computer is incredibly fast, accurate, and stupid; man is unbelievably slow, inaccurate, and brilliant; together they are powerful beyond imagination.

Reply





Messages In This Thread
Guess random number - by Vi-Sion - 04-02-2017, 01:27 PM
RE: Guess random number - by Pikami - 04-02-2017, 01:41 PM
RE: Guess random number - by Vi-Sion - 04-02-2017, 01:47 PM
RE: Guess random number - by Pikami - 04-02-2017, 01:53 PM
RE: Guess random number - by Vi-Sion - 04-02-2017, 01:55 PM
RE: Guess random number - by Pikami - 04-02-2017, 02:02 PM
RE: Guess random number - by Vi-Sion - 04-02-2017, 02:12 PM
RE: Guess random number - by Pikami - 04-02-2017, 02:45 PM
RE: Guess random number - by Vi-Sion - 04-02-2017, 08:24 PM
RE: Guess random number - by FutileRmnc - 11-09-2017, 05:44 AM
RE: Guess random number - by darkmelody - 11-12-2017, 07:44 AM