Created
August 10, 2011 01:14
-
-
Save susanBuck/1135763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Random Drawing</title> | |
<style type='text/css'> | |
* { | |
font-family:Helvetica; | |
font-size:35pt; | |
} | |
.wrapper { | |
width:550px; | |
border:1px dotted grey; | |
padding:10px; | |
margin:0px auto; | |
text-align:center; | |
} | |
.box { | |
border:1px solid black; | |
width:530px; | |
height:60px; | |
margin:10px; | |
text-align:center; | |
} | |
.winner { | |
background-color:cyan; | |
} | |
</style> | |
</head> | |
<body> | |
<div class='wrapper'> | |
<?php | |
# Who are our contestants? | |
$contestants[] = "Bob"; | |
$contestants[] = "Frank"; | |
$contestants[] = "Emily"; | |
$contestants[] = "Bo"; | |
$contestants[] = "Sandy"; | |
$contestants[] = "Elizabeth"; | |
$contestants[] = "Joey"; | |
# Pick and print a winning number | |
$winning_number = rand(1,sizeof($contestants)); | |
echo "The winning number is $winning_number!"; | |
# Loop through contestants, seeing if any won | |
foreach($contestants as $this_contestant) { | |
# Generate a random number | |
$random_number = rand(1,sizeof($contestants)); | |
# See if their generated random number mathches the winning number | |
if($random_number == $winning_number) { | |
# If it does, we'll set a class called winner | |
$class = 'winner'; | |
} | |
else { | |
# If it does not, we won't add on a class | |
$class = ''; | |
} | |
# Print the boxes | |
echo "<div class='box ".$class."'>"; | |
echo $this_contestant." (".$random_number.")<br>"; | |
echo "</div>"; | |
} | |
?> | |
Refresh to play again | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment