Guest User

Untitled

a guest
Mar 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // Not working - example of spread
  12.  
  13. const gameOver = results => console.log(`Game Over - ${results}`)
  14. // function to log the results when game is over
  15.  
  16.  
  17. const rollAgain = point =>
  18. console.log(`The point is ${point}, try again`)
  19.  
  20.  
  21. const craps = (roll, point) => new Promise((gameOver, rollAgain) => {
  22.  
  23. //if roll is not sent as a number between 2 and 12, rollAgain
  24. if (!roll || typeof roll !== "number" || roll <2 || roll >12){
  25. rollAgain("to roll a number")
  26. }
  27.  
  28. // If point is not set, this must be the first roll, the come out roll
  29. else if (!point){
  30.  
  31. if (roll ===7 || roll === 11){
  32. gameOver("You win by natural")
  33.  
  34. } else if (roll ===2 || roll === 3){
  35. gameOver("You have lost, crapped out")
  36.  
  37. }else {
  38. rollAgain(roll)
  39. }
  40.  
  41. }else if (roll === point){
  42. gameOver("You win, you hit the point")
  43. }else {
  44. if (roll === 7) {
  45. gameOver ("you loose, craps")
  46. }else {
  47. rollAgain(point)
  48. }
  49. }
  50.  
  51. })
  52.  
  53. craps("foo").then(gameOver, rollAgain ) // The point is to roll a number, try again
  54. craps(7).then(gameOver, rollAgain ) // Game Over - You win by natural
  55. craps(2).then(gameOver, rollAgain ) // Game Over - You lose, crapped out
  56. craps(8).then(gameOver, rollAgain ) // The point is 8, try again
  57. craps(5,8).then(gameOver, rollAgain ) // The point is 8, try again
  58. craps(7,8).then(gameOver, rollAgain ) // Game over - You lose, craps
  59. craps(8,8).then(gameOver, rollAgain ) // Game over - You win, you hit the point
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. )
  68. </script>
  69.  
  70.  
  71.  
  72. <script id="jsbin-source-javascript" type="text/javascript">// Not working - example of spread
  73.  
  74. const gameOver = results => console.log(`Game Over - ${results}`)
  75. // function to log the results when game is over
  76.  
  77.  
  78. const rollAgain = point =>
  79. console.log(`The point is ${point}, try again`)
  80.  
  81.  
  82. const craps = (roll, point) => new Promise((gameOver, rollAgain) => {
  83.  
  84. //if roll is not sent as a number between 2 and 12, rollAgain
  85. if (!roll || typeof roll !== "number" || roll <2 || roll >12){
  86. rollAgain("to roll a number")
  87. }
  88.  
  89. // If point is not set, this must be the first roll, the come out roll
  90. else if (!point){
  91.  
  92. if (roll ===7 || roll === 11){
  93. gameOver("You win by natural")
  94.  
  95. } else if (roll ===2 || roll === 3){
  96. gameOver("You have lost, crapped out")
  97.  
  98. }else {
  99. rollAgain(roll)
  100. }
  101.  
  102. }else if (roll === point){
  103. gameOver("You win, you hit the point")
  104. }else {
  105. if (roll === 7) {
  106. gameOver ("you loose, craps")
  107. }else {
  108. rollAgain(point)
  109. }
  110. }
  111.  
  112. })
  113.  
  114. craps("foo").then(gameOver, rollAgain ) // The point is to roll a number, try again
  115. craps(7).then(gameOver, rollAgain ) // Game Over - You win by natural
  116. craps(2).then(gameOver, rollAgain ) // Game Over - You lose, crapped out
  117. craps(8).then(gameOver, rollAgain ) // The point is 8, try again
  118. craps(5,8).then(gameOver, rollAgain ) // The point is 8, try again
  119. craps(7,8).then(gameOver, rollAgain ) // Game over - You lose, craps
  120. craps(8,8).then(gameOver, rollAgain ) // Game over - You win, you hit the point
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. )</script></body>
  129. </html>
Add Comment
Please, Sign In to add comment