Magic 8-ball

Write an R function magic.8ball( that outputs one the following statements when called.

  1. ‘I don’t see that happening.’
  2. ‘You must be dreaming.’
  3. ‘Chances are good.’
  4. ‘If you work hard and stay focused, then this might happen.’
  5. ‘When the sun shines, it shines on your face.’
  6. ‘Definitely going to happen!’
  7. ‘Take some time to think about it.’
  8. ‘This is not a good idea!’
  9. ‘This is a great idea!’
  10. ‘Cannot be determined at this time. Try Again!’

Advanced - Include an optional argument named x.seed that controls the seed for the random number generator. The default definition of x.seed should allow the magic.8ball() to be random, but its existence will allow you to manually control the seed value and produce the same output from the magic.8ball() each time.

Function

#==============================================================================
# Function
#==============================================================================
magic.8ball = function(x.seed){
    if (!missing(x.seed)){
        set.seed(x.seed)
    }
    sample(c("I don't see that happening.", 
             "You must be dreaming.", 
             "Chances are good.", 
             "If you work hard and stay focused, then this might happen.", 
             "When the sun shines, it shines on your face.", 
             "Definitely going to happen!", 
             "Take some time to think about it.", 
             "This is not a good idea!", 
             "This is a great idea!", 
             "Cannot be determined at this time. Try Again!"), 1)
}

Function Call

#==============================================================================
# x.seed value = FALSE
#==============================================================================
magic.8ball()
magic.8ball()
magic.8ball()
## [1] "When the sun shines, it shines on your face."
## [1] "If you work hard and stay focused, then this might happen."
## [1] "When the sun shines, it shines on your face."
#==============================================================================
# x.seed value = TRUE
#==============================================================================
magic.8ball(x.seed = 123)
magic.8ball(x.seed = 123)
magic.8ball(x.seed = 123)
## [1] "Chances are good."
## [1] "Chances are good."
## [1] "Chances are good."
# Session Info
sessionInfo()
## R version 3.3.1 (2016-06-21)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 10586)
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] magrittr_1.5    formatR_1.4     tools_3.3.1     htmltools_0.3.5
##  [5] yaml_2.1.13     Rcpp_0.12.5     stringi_1.1.1   rmarkdown_1.0  
##  [9] knitr_1.13.1    stringr_1.0.0   digest_0.6.9    evaluate_0.9