Tony's String Guess Game
Riddle:
I'm spotty and speedy, but not at all greedy. I look like a leopard but don't try to play me at cards. What am I?hint: The string has 7 characters.
hint: The string has 7 characters.
<?php
include('includes/header.php');
echo "<h2>Tony's String Guess Game</h2>";
// strings
$riddle = "I'm spotty and speedy, but not at all greedy. I look like a leopard but don't try to play me at cards. What am I?";
$answer = "Cheetah";
// guess logic
if (!isset($_POST['guess']))
{
echo "<p><h2>Riddle:</h2> $riddle</p>";
echo "<p>hint: The string has " . strlen($answer) . " characters.</p>";
echo '<form method="POST">';
echo '<input type="text" name="guess">';
echo "<br><br>";
echo '<input type="submit" value="Submit">';
echo '</form>';
echo "<br><br>";
}
else // checks guess and show result
{
$guess = trim($_POST['guess']);
$guess = strtolower($guess);
$answerCheck = strtolower($answer);
if ($guess == $answerCheck)
{
echo "<h3>Correct!</h3>";
echo "<p>The answer was: <strong>$answer</strong></p>";
echo "<img src='images/cheetah.gif' width='498' height='280' alt='cheetah' title='cheetah'>";
echo '<form method="POST">';
}
else
{
echo "<h3>Wrong answer. Try again!</h3>";
echo "<p>Your guess was: $guess</p>";
echo "<p>Hint: The string has " . strlen($answer) . " characters.</p>";
echo '<form method="POST">';
echo '<input type="text" name="guess">';
}
echo "<br><br>";
echo '<input type="submit" value="Try Again">';
echo "<br><br>";
echo '</form>';
}
include 'includes/footer.php';
?>