Dice Roller
UI Coding
Easy
20 min
forms
css
accessibility
randomness
Build a dice roller for six-sided dice.
Requirements
- A Number of dice input (whole number from 1 to 12, default 3) and a Roll button. Submitting the form rolls.
- Show each die as a face with the right pip layout (draw it with HTML and CSS, not the ⚀–⚅ characters or images).
- Every value is uniformly random from 1 to 6.
- Show the total below the dice ("Total: 14").
- Invalid counts show an error (
aria-invalid+ linked message) and don't roll. - Accessibility:
- each die is announced as "Die showing 4", and the pips themselves are hidden
- after a roll, screen-reader users hear the result without moving focus, for example "Rolled 3 dice: 4, 6, 4. Total 14."
- Before the first roll, show a hint ("Choose how many dice and press Roll").
Follow-up
Math.floor(Math.random() * 6) + 1: is it uniform? When would you usecrypto.getRandomValues?- Add a short "shake" animation without breaking
prefers-reduced-motion. - How do you test code that depends on randomness?
Spotted a mistake or a rights concern? Report an issue