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


#1

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 ?


#2

@balloocode

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


#3

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 !


#4

@balloocode

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:

console.log(rand(1,6));

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


#5

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:


#6

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


#7

Ok.

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


#8

@balloocode

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.


#9

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 ...


#10

@balloocode

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:


#11

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?


#12

@balloocode

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:


#13

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?

Look!








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


<?php
$headCount = 0;
$flipCount = 0;
while ($headCount < 1) {
$flip = rand(0,1);
$flipCount ++;
if ($flip){
$headCount ++;
echo "
6
";
}
else {
$headCount = 0;
echo "
1
";
echo "
2
";
echo "
3
";
echo "
4
";
echo "
5
";
}
}
echo "<p>It took {$flipCount} flips!</p>";
?>
</body>


#14

@balloocode

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?


#15

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)


#16

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!!)


#17

@balloocode

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