How to simulate rolling two dice (game cubes) with values 1–6 in JavaScript

1 Answer

0 votes
function rollDice() {
  return Math.floor(Math.random() * 6) + 1; // 1–6 inclusive
}

const dice1 = rollDice();
const dice2 = rollDice();

console.log("Dice 1:", dice1);
console.log("Dice 2:", dice2);



/*
run:

Dice 1: 5
Dice 2: 6

*/

 



answered Feb 18 by avibootz

Related questions

...