Get startedGet started for free

Function to keep rolling when point is established

Let us code the function that will handle all rolling that occurs after a point has been established. Recall that this means it should continue rolling until either the point is rolled again, or a 7 is rolled. Once either of these happens, it should stop, and report back whether the result is a win or a loss.

Note that within this function, we will again use the roll_dice function that we previously defined.

This exercise is part of the course

Probability Puzzles in R

View Course

Exercise instructions

  • Fill in the conditions in the while loop to continue rolling until either a 7 or the point is rolled.
  • Fill in the condition to check if the most recent roll will result in a win.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

roll_after_point <- function(point){
  new_roll <- 0
  # Roll until either a 7 or the point is rolled 
  while( ___ ){
    new_roll <- roll_dice(2)
    if(new_roll == 7){
      won <- FALSE      
    }
    # Check whether the new roll gives a win
    if(___ == ___){
      won <- TRUE
    }
  }
  return(won)
}
Edit and Run Code