.. | ||
index.html | ||
README.md | ||
script.js | ||
style.css |
Dice Component - Interactivity
The provided JavaScript code defines two classes: Dice
and
DiceButton
. These classes work together to create a web component
that simulates rolling a dice.
- The
Dice
class provides a simple API for simulating a die roll, using a static method to shuffle the array of die faces and an instance method to perform the roll. - The
DiceButton
class extendsHTMLElement
to create a custom web component that encapsulates aDice
instance. It defines the structure of the component and handles user interactions through theconnectedCallback
andhandleEvent
methods. - Upon clicking the button, the
handleEvent
method updates the component's display to show the result of the die roll.