Micaela's String Guess Game
Riddle:
I move slowly and carry my home.hint: The string has 6 characters.
CODE FOLLOWS
<?php
include('../includes/header.php');
echo "<h2>Micaela's String Guess Game</h2>";
// strings
$riddle = "I move slowly and carry my home.";
$answer = "turtle";
// 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/happyturtle.gif' width='200'>";
echo '<form method="POST">';
echo "<br><br>";
echo '<input type="submit" value="Try Again">';
echo "<br><br>";
echo '</form>';
}
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');
?>