Dice - Web Component
✓ Published0🌍 Public
Aangusgrant
Last edited Mar 3, 2023
Created on Mar 3, 2023
This example demonstrates a custom web component called `roll-dice` that simulates rolling a six-sided die. The component displays a button and an accessible live region; clicking the button triggers a shuffle of the dice sides array, and the resulting value is announced in the `aria-live` region. It uses the custom elements API via `HTMLElement` and `customElements.define`, with a static private shuffle method that implements the Fisher–Yates algorithm. No external libraries are used; the behavior is self-contained in the component’s constructor and callbacks.
AI-generated description