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

1 Answer

0 votes
function rollDice(): number {
  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:",  4 
"Dice 2:",  5 
  
*/

 



answered Feb 18 by avibootz

Related questions

...