Five-dice tray with holds and up to three rolls per turn
Build the dice tray from a push-your-luck dice game. Each turn, the player rolls five six-sided dice up to three times. Between rolls they can hold any dice they like: held dice keep their value, and only the others are rolled again.
The starter code includes the settings:
const DICE_COUNT = 5;
const MAX_ROLLS = 3;
<button>s, left to right. A die’s text is its value as a single digit (1 to 6). Before the first roll of a turn, dice show no digit (for example –) and are disabled.Rolls left: N, starting at Rolls left: 3, and Total: N, the sum of the dice (Total: 0 before the first roll).Math.floor(Math.random() * 6) + 1, calling Math.random() once per rolled die, from left to right. Held dice don’t call it.aria-pressed="true", other dice have aria-pressed="false". Holds stay in place across rolls until the player clicks the die again.Turn over.Rolls left: 3, Total: 0, and no Turn over.Math.random() returns 0.7, 0.1, 0.75, 0.3, 0.5
Click Roll dice 5 1 5 2 4 Total: 17 Rolls left: 2
Hold dice 1 and 3
Math.random() returns 0.9, 0.95, 0.99
Click Roll dice 5 6 5 6 6 Total: 28 Rolls left: 1
Hold all five Roll is disabled
Release die 2, click Roll Rolls left: 0, "Turn over", Roll is disabled
Math.random() while rendering (for example for a rolling animation), and don’t call it for held dice.The tests replace Math.random with a stub that returns chosen numbers and counts its calls, click your buttons, and read the screen like a user would. You don’t need test ids or specific class names. They check that:
role="button" elements), in DOM order, whose text doesn’t contain “Roll” or “New turn”. A die’s value is the digit in its text.disabled attribute or aria-disabled="true", and holding is read from aria-pressed.Rolls left: N, Total: N and Turn over appear as described.Math.random() is called exactly once per rolled die.Capitalization and extra spacing don’t matter.