I want change the face of coins for diced launched? Can you help me please!


Hi , does anyone can help me please , I would do the same loop but instead of coins , I would do it with diced launched ! But as there are six faces on a die , I do not know how to do ?



Well, it depends on what you want to get every time you throw the die.


Already thank you for your reply. In fact I would do the same with the parts , but for the six sides of the dice. The problem is that I do not know how to get with ( Math.random ) , a random outcome for each side of the die as (random ) is limited to 0 or 1. So my question is how can I do? Regardless of the chosen face is the execution of the loop that is a mystery to me !



Remember in PHP, we have a function called rand() which takes in parameter two integer: the start and the end. It is going to output a different number everytime between the start and the end. Per example, we have 6 faces:


This code is going to print a random number between 1 and 6 (well, the one and the six are included).

P.-S Math.random is javascript, not PHP


Oh ok thank you . Yes rand () sorry, that was to be more understandable, my English is not great !! So if I understand I will need a rand (0.1 ) for each side of the die in a switch statement ?
Or rand (1,6) once? Thanks Emily :wink:


Use rand(1,6) because with rand(0,1) for each side of the die is going to be complicated.



I try but I still do not see how I could do with loop while it's possible?



Again, this depend on which kind of thing you want to get when you throw your die. Per example, if you want the die to land on 4, then you will write a while loop for when you land on 4.


Here is what I would like this to happen. For example I would like to roll the dice to get the face 6 and it prints my face 6 in the console, but as I do not get 6, I would like him to show the other sides randomly. For example it is the opposite one that falls, I raise the die face 2 I raise the die, ect .. . As if I roll a die simply made ​​up to get 6 or another. Excuse me if I make you waste your time ...



Ok so you want each time they get six, it will print six in the console. If they don't get 6, it will print the other sides randomly (uh, sorry I don't understand). If it's opposite one that falls (uh the opposite of one or one) you raise the die (why do you raise the die?). Sorry, I don't understand what your saying when it comes to other than 6. :disappointed:


This is because I use the translator is not great sorry :worried:
It is not serious , i would do when I understand a little better :slightly_smiling:

I have a question for you and after I stop to annoy you !
Programmer is your job? You passed by a university or something like this to learn or you learned alone?



Well, I'm not programming stuff for money. I'm currently a highschooler self-learning coding. Google is my friend and Codeacademy too :slightly_smiling:


Ok, so it's a hobby ! You come to teach others ? Well, I think you will not waste your time for nothing !! Amazing! I think I managed well almost!

So it's almost what I want ! I roll the die is when I get 6 it appears on one die , but the other numbers they appear on several dice. And I wish there was one digit at a time. You know what I mean?


We are going to flip a dice until we get one head in a row!

$headCount = 0;
$flipCount = 0;
while ($headCount < 1) {
$flip = rand(0,1);
$flipCount ++;
if ($flip){
$headCount ++;
echo "
else {
$headCount = 0;
echo "
echo "
echo "
echo "
echo "
echo "<p>It took {$flipCount} flips!</p>";



Oh!!! So if I understand, if the die gives a 6 when you throw it, you print 6. Otherwise you print all the other numbers apart from six if the number you get in the die is different than 6. Am I right?


yes almost , but I just want a face by a face!

Like that : face 1 (not 6 or other it's for example reroll the dice)


face 2 (not 6 reroll)

face 3 (not 6 reroll)

face 4 (not 6 reroll)

face 5 (not 6 reroll)

face 6 (it's 6 youhouuu it's fabulous!!)



So, if you get a number other than six, you will reroll the dice until you get 6 if I understand?