//COMS 161.01 11/03/2017 // //A PROGRAM THAT PLAYS A GAME OF Craps // //On the 1st roll, you lose if you roll a 2,3,or 12, //but you win if you roll a 7 or 11. // //In all other cases, this 1st roll is saved as the "point" //and you must roll until either you match the point (a win) //or you roll a 7 (a loss). die1 = 1 + Math.floor(6 * Math.random()); die2 = 1 + Math.floor(6 * Math.random()); result = die1 + die2; alert("You rolled a " + result); if (result == 2 || result == 3 || result == 12) alert("You lost."); else if (result == 7 || result == 11) alert("You won."); else { point = result; //SAVE result AS point alert("You need to roll a " + point + " before rolling a 7."); die1 = 1 + Math.floor(6 * Math.random()); die2 = 1 + Math.floor(6 * Math.random()); result = die1 + die2; while (result!=point && result!=7) { alert("You rolled a " + result); die1 = 1 + Math.floor(6 * Math.random()); die2 = 1 + Math.floor(6 * Math.random()); result = die1 + die2; } alert("You rolled a " + result); if (result==point) alert("You won."); else alert("You lost."); } //end else