Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var diceThrow = function () {
- dice1 = Math.floor((Math.random()*6)+1);
- dice2 = Math.floor((Math.random()*6)+1);
- sumOfDices = dice1 + dice2;
- console.log("You threw a " + dice1 +
- " and a " + dice2 + " for a combined score of " + sumOfDices);
- return sumOfDices;
- };
- var status;
- var score;
- var myPoint;
- score = diceThrow();
- switch (score) {
- case 7:
- case 11:
- status = "Wins";
- break;
- case 2:
- case 3:
- case 12:
- status = "Loses";
- break;
- default:
- status = "Continue";
- myPoint = score;
- console.log("Your score is " + score);
- }
- while (status === "Continue") {
- score = diceThrow();
- if (score === myPoint) {
- status = "Wins";
- }
- else if (score === 7) {
- status = "Loses";
- }
- }
- if (status === "Wins" ) {
- console.log("Player won this round!");
- }
- else {
- console.log("Player lost this round");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement