Thank you it works, the picture comes up with the roll and everything. One minor little problem though. If the correct number is picked it gives me the Illegal State Error, instead of the 'You got it right message'.
So, guess I didn't check it out far enough the first time. What am I doing wrong? Is it in the way I have the else if ($diceroll != 1 && $pick == 1)? 😕
<?php
srand ((double) microtime() * 10000000);
$diceroll = rand(1, 6);
//starting index is zero
$arrPics = array(' ', 'die1.gif', 'die2.gif', 'die3.gif', 'die4.gif', 'die5.gif', 'die6.gif');
print "<img src=\"" . $arrPics[$diceroll] . "\">";
if ($roll == 1 && $pick == 1) {
print '<font color="blue"> You got it right! </font>';
} elseif ($diceroll != 1 && $pick == 1) {
print '<font color="red"> You got it wrong! </font>';
} elseif ( $diceroll == 2 && $pick == 2) {
print '<font color="blue"> You got it right! </font>';
} elseif ($diceroll != 2 && $pick == 2) {
print '<font color="red"> You got it wrong! </font>';
} elseif ( $diceroll == 3 && $pick == 3) {
print '<font color="blue"> You got it right! </font>';
} elseif ($diceroll != 3 && $pick == 3) {
print '<font color="red"> You got it wrong! </font>';
} elseif ( $diceroll == 4 && $pick == 4) {
print '<font color="blue"> You got it right! </font>';
} elseif ($diceroll != 4 && $pick == 4) {
print '<font color="red"> You got it wrong! </font>';
} elseif ( $diceroll == 5 && $pick == 5) {
print '<font color="blue"> You got it right! </font>';
} elseif ($diceroll != 5 && $pick == 5) {
print '<font color="red"> You got it wrong! </font>';
} elseif ( $diceroll == 6 && $pick == 6) {
print '<font color="blue"> You got it right! </font>';
} elseif ($diceroll != 6 && $pick == 6) {
print '<font color="red"> You got it wrong! </font>';
} else {
print "<br>Illegal state error!";
}
?>
I know there has to be a shorter way of doing this too, but being a newbie we tend to take the hardest road cause its the only road we know. And well, I guess I don't know this road very well at all yet. :bemused:
Suggestions appreciated and thank you for the advice on getting the pictures and die to match up. That works slick.
Talia