Skip to content

Instantly share code, notes, and snippets.

@CernerJT
Created October 1, 2014 02:36
Show Gist options
  • Save CernerJT/1bc7da59b4052771be56 to your computer and use it in GitHub Desktop.
Save CernerJT/1bc7da59b4052771be56 to your computer and use it in GitHub Desktop.
Day 18: Trivia Night Done Right!
<html><head><title>Trivia Night!</title></head><body><h1>Trivia Round 1: Ponies, Power Rangers, or Pokémon!</h1><form method="GET" action="quiz.php">
<p>Please choose whether each item is a Pokémon, a Power Ranger character (any series), or a character from "My Little Pony: Friendship is Magic"</p><?
# One of my favorite things about the Engineering Health culture is the trivia nights. We typically have two
# Trivia nights a year. Once during our annual DevCon conference, and one on Programmer Day. This year we
# dominated. Well, almost. We got third. But it was close! Now if this was a category, we would have won!
class TriviaItem { public $name; public $type; function __construct($name, $type) { $this->name = $name; $this->type = $type; } };
$items=[new TriviaItem("Zororak","Pokémon"), new TriviaItem("Zorua", "Pokémon"), new TriviaItem("Zordon", "Power Rangers"), new TriviaItem("Zygarde", "Pokémon"),
new TriviaItem("Ziggy", "Power Rangers"), new TriviaItem("Zurgane", "Power Rangers"), new TriviaItem("Zirconic", "My Little Pony: Friendship is Magic"), new TriviaItem("Zirtrax", "Power Rangers")];
$options=["-- Select --", "Pokémon", "Power Rangers", "My Little Pony: Friendship is Magic"];
$i = 1;
echo "<table><tbody>";
foreach($items as $item){
echo "<tr><td>$i.</td><td>{$item->name}</td><td><select name='{$item->name}' sel>";
foreach ($options as $option){
$selected = $_GET[$item->name] === $option ? "selected='selected'" : "";
echo "<option $selected>{$option}</option>";
}
echo "</select></td>";
if (isset($_GET[$item->name])){
if ($_GET[$item->name] === $item->type){
echo "<td><span style='color:green'>Right!</span></td>";
}
else{
echo "<td><span style='color:red'>Wrong!</span></td>";
}
}
echo "</tr>";
$i++;
}
echo "</tbody></table>";
?><input type="submit" /></form></body></html>
@CernerJT
Copy link
Author

Hmm.... This one's a bit tough to tell if it's less than 32 "lines" of code. If the terminal symbol is a ; then this has 12 lines in it... Then I close 8 tags, so that's might count for 8 more lines? But then I dynamically produce markup... It's hard telling. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment