Lesson goal: Rolling a dice, twice

Previous: Picking blue, white, and red balls | Home | Next: Not rolling a 7 or 11

Let's roll one dice two times, and ask some questions about our rolls. In this case, let's see what the probability as a whole is, of getting 4, 5, or 6 on the first roll, and a 1, 2, 3, or 4 on the second roll.

As in last lessons, we'll set N equal to the number of rolls we'd like to make. Next, we'll set up a "roll for-loop" for each roll. The first one study what the probability is to roll a 4, 5, or 6 on dice #1. The second will look for the probability of rolling a 1, 2, 3. A dice roll will be simulated with math.random(1,6).

Note here that we have two separate results, d1 and d2. d1 will be the chance of rolling a 4, 5, or 6. d2 will be the chance of rolling a 1, 2, 3, or 4.

Note a key word in the question, the "and": "getting a 4, 5, or 6 on the first roll and a 1, 2, 3, or 4 on the second roll. "And" in probability means to multiply any separate and independent probabilities, so in the end, we multiply d1 and d2 to find the final answer.

Now you try. Run as is, or change up the numbers to look for on the rolls.

Type your code here:


See your results here: