Hello,
I wasn't sure if there was a "beginner php questions" area, so sorry if this is not put in the right spot, but I have a very basic "game" where it prints out a randomly generated low card and high card. The low card has to be of a lower value than the high card, and they cant equal each other or be within 1 of each other. I have this all working fine. The problem is, when I try to add in any kind of way to change numbers, say, 11-14 to Jack, Queen, King, Ace, the whole lower card being lower than the high card goes out the window. I feel like I'm maybe approaching this from the completely wrong direction or something, so if anyone could give me any kind of advice, I'd be very grateful.
<?php
function deal() {
$card = rand(1,52);
return $card;
}
$highCard = deal();
do {
$lowCard = deal();
}
while ($lowCard > $highCard || $highCard - $lowCard <= 1);
function cardValue($card) {
if ($card % 14 === 0 || $card % 14 === 1) {
return $card = "an Ace";
} else if ($card % 14 === 13) {
return $card = "a King";
} else if ($card % 14 === 12) {
return $card = "a Queen";
} else if ($card % 14 === 11) {
return $card = "a Jack";
} else {
return $card % 13;
}
}
print "Your low card is " .cardValue($lowCard). " and your high card is " .cardValue($highCard);
?>