-
-
Save sethschori/2e36c03dff6de521cbd5391a0cec5a43 to your computer and use it in GitHub Desktop.
https://repl.it/CRu0/106 created by sethopia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
HOLY CRAPS | |
We're creating a simplified verison of the popular casino game craps. | |
A player rolls 2 dice. If the total of those dice is 7 or 11, the player wins, | |
otherwise he or she must add more money to the betting pool and roll again | |
Complete the while loop and run your code to play some craps! | |
*/ | |
var bettingPool = 0; | |
function roll() { | |
//We use Math.random() to generate a random number between 0 and 1. Using Math.floor() and some arithmetic lets us simulate rolling a 6-sided die | |
var d1 = Math.floor(Math.random() * 6) + 1; | |
var d2 = Math.floor(Math.random() * 6) + 1; | |
console.log("I rolled a " + d1 + " and a " + d2); | |
while(d1 + d2 !== 7 && d1 + d2 !== 11) { | |
console.log("Roll Again!") | |
bettingPool += 100; | |
d1 = Math.floor(Math.random() * 6) + 1; | |
d2 = Math.floor(Math.random() * 6) + 1; | |
} | |
console.log("Woohoo! I won " + bettingPool); | |
} | |
roll() | |
/* | |
When you're done, see if you can add more craps rules. Totals of 7 and 11 are winning, | |
but 2,3,12 will make you "crap out" and lose. How can you add losing functionality to this game? | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Native Browser JavaScript | |
>>> I rolled a 2 and a 3 | |
Roll Again! | |
Roll Again! | |
Roll Again! | |
Roll Again! | |
Woohoo! I won 400 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment