'F' → Fullscreen
rollDie() that prints the die result.
function rollDie() { let die = Math.floor(Math.random() * 6) + 1; console.log("Rolled: " + die);}
console.log("--- CRAPS ---");// Call several times to verify randomnessrollDie();rollDie();rollDie();rollDie() so it returns the value
instead of printing it.
rollDie() twice
and print both results.
function rollDie() { let die = Math.floor(Math.random() * 6) + 1; console.log("Rolled: " + die); return Math.floor(Math.random() * 6) + 1;}
console.log("--- CRAPS ---");
rollDie();rollDie();rollDie();
let d1 = rollDie();let d2 = rollDie();
console.log("You rolled: " + d1 + " and " + d2);rollDice() that calls rollDie() twice, prints the breakdown, and returns the total.
rollDice() by calling it and printing
the total.
function rollDie() { return Math.floor(Math.random() * 6) + 1;}
function rollDice() { let die1 = rollDie(); let die2 = rollDie(); let total = die1 + die2;
console.log("You rolled " + die1 + " + " + die2 + " = " + total); return total;}
console.log("--- CRAPS ---");let total = rollDice();console.log("Total: " + total);evaluateComeOutRoll(roll) to print
the outcome and return whether the round is over (true or false).
point variable.
function rollDie() { return Math.floor(Math.random() * 6) + 1;}
function rollDice() {6 collapsed lines
let d1 = rollDie(); let d2 = rollDie(); let total = d1 + d2;
console.log("You rolled " + d1 + " + " + d2 + " = " + total); return total;}
function evaluateComeOutRoll(roll) { if (roll == 7 || roll == 11) { console.log("Rolled a " + roll + "! You win!"); return true; } else if (roll == 2 || roll == 3 || roll == 12) { console.log("Rolled a " + roll + ". You lose."); return true; } else { console.log("Rolled a " + roll + "."); return false; }}
console.log("--- CRAPS ---");
let point = 0;
let roll = rollDice();let roundOver = evaluateComeOutRoll(roll);
if (!roundOver) { point = roll; console.log("The point is now " + point + "."); // Next step: loop while not over and resolve the point.}evaluatePointRoll(roll, point) and use
a
while loop to keep rolling until the player
wins or loses.
function rollDie() { return Math.floor(Math.random() * 6) + 1;}
function rollDice() {6 collapsed lines
let d1 = rollDie(); let d2 = rollDie(); let total = d1 + d2;
console.log("You rolled " + d1 + " + " + d2 + " = " + total); return total;}
function evaluateComeOutRoll(roll) {12 collapsed lines
if (roll == 7 || roll == 11) { console.log("Rolled a " + roll + "! You win!"); return true; } else if (roll == 2 || roll == 3 || roll == 12) { console.log("Rolled a " + roll + ". You lose."); return true; } else { console.log("Rolled a " + roll + "."); return false; }}
// Step 5: resolve after point is setfunction evaluatePointRoll(roll, point) { if (roll == point) { console.log("Rolled a " + roll + "! You win!"); return true; } else if (roll == 7) { console.log("Rolled a 7. You lose."); return true; } else { console.log("Rolled a " + roll + ". Still shooting for " + point + "."); return false; }}
console.log("--- CRAPS ---");
let point = 0;let gameOver = false;
// Come-out rolllet roll = rollDice();gameOver = evaluateComeOutRoll(roll);
if (!gameOver) { point = roll; console.log("The point is now " + point + ".");
// Keep rolling until win (hit point) or lose (7) while (!gameOver) { roll = rollDice(); gameOver = evaluatePointRoll(roll, point); }}
console.log("Thanks for playing!");--- CRAPS ---You rolled 4 + 3 = 7Rolled a 7! You win!Thanks for playing!
Submit your completed .js file and reflection
answers to the appropriate dropbox.