leanwebclub/structure-and-scale/dice-component-interactivity/README.md

856 B

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 extends HTMLElement to create a custom web component that encapsulates a Dice instance. It defines the structure of the component and handles user interactions through the connectedCallback and handleEvent methods.
  • Upon clicking the button, the handleEvent method updates the component's display to show the result of the die roll.

References