function rollDice() { // Math.random() generates a floating-point number between 0 (inclusive) and 1 (exclusive). // Multiplying by 6 gives a number between 0 (inclusive) and 6 (exclusive). // Math.floor() rounds this number down to the nearest whole integer (0-5). // Adding 1 shifts the range to 1-6, simulating a standard six-sided die. return Math.floor(Math.random() * 6) + 1; } // Example usage: const diceResult = rollDice(); console.log(`You rolled a: ${diceResult}`);