Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Php help Re: Php help

#116113
__
Participant

Your code works perfectly. However, it probably does not do what you intended.

// you defined $x as a _string_.
// “rand int(1,20)” <-- not a function.
// just a sentence.
$x = ‘rand int(1,20)’;

// here, you cast the string to an integer
// (because you’re comparing it to an integer).
// ‘rand …’ equates to (0).
if ($x <= 9 ){
// therefore,
// the comparison is always TRUE
echo “

congrats”;
}elseif($x >= 10 ){

// and never FALSE.
echo “you lose”;
}

You probably meant to do this:

// no quotes or “int”
$x = rand( 1,20 );

The rest of your code should work as expected after that.

(Though you don’t need the `elseif`; you could use just `else` and get the same result.)