Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlex Young
4,265 Pointsif statement query?
Hi,
I'm trying to put everything i've learnt plus a little research but it's working with rolling the dice i get numbers from 0-6 fine but my if statement is not working
<?php $numbers = array('1','2','3','4','5','6'); ?>
<form action="index.php" class="dice" name="dice"> <input type="submit" value="Roll">
<?php echo(array_rand($numbers,1)); ?>
</form>
<?php
if ($numbers > 3) { echo "You Rolled a high number"; } else { echo "Not Today"; }
?>
Alex Young
4,265 PointsNope was just random idea to practice if statement, array really and just building it up more i learn
Konrad Pilch
2,435 Pointsaa okay . I think you might try swich too , if php has it, but it should xd im new to this too but how im learning is that im doing things i want , so i went throw the treehouse tutroaials, some of them and then i went off doing registration form and so on . But i like the small ideas like making the dice :) teach small things that will be for sure cool but what more improve on the skill .
Happy Coding! :) :D
2 Answers
Brad Van Skyhawk
28,489 PointsHi,
You need a assign you random number to a variable and then test it. You are using the array in your if statement.
For example:
<?php $num = array_rand($numbers,1); if ($num > 3) { echo "You Rolled a high number"; } else { echo "Not Today"; }
Alex Young
4,265 PointsThank you :)
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsHI, a bit off the topic but could i ask you what game are you doing? are you just making a rolling dice that displays a number or you make the computer guess and you roll the cide and it tells you your if statement ?