Can anybody help with this basic function excercise
Posted: Tue Jul 28, 2009 1:04 pm
Hi,
I am trying to figure out how to write a function (or combination of functions) that will perform the same action as this code
Basially $bet contains the term "even" or "odd". The aim is to select even or odd on a form, and if the sum of the two dice is odd or even (depending on what you selected), you win.
I have tired a few different things that didnt work and I'm sure its a fairly simple function.
Any help or suggestions will be greatly appreciated
Thanks very much.
I am trying to figure out how to write a function (or combination of functions) that will perform the same action as this code
Code: Select all
$bet = $_GET['bet'];
if ( ( $bet == 'even' && ( rand(1, 6) + rand(1, 6) ) % 2 == 0 ) ||
( $bet == 'odd' && ( rand(1, 6) + rand(1, 6) ) % 2 != 0 ) )
{
echo '<p>You win!</p>';
}
else
{
echo '<p>You lose!</p>';
}
I have tired a few different things that didnt work and I'm sure its a fairly simple function.
Any help or suggestions will be greatly appreciated
Thanks very much.