Skip to main content

Dice - ES Modules

✓ Published0🌍 Public
Aangusgrant
Last edited Mar 4, 2023
Created on Mar 4, 2023

This example demonstrates how JavaScript ES Modules enable code reuse by separating dice-rolling logic into an external file. The page imports the `d6` and `d20` functions from `roll.js`, rolls one six-sided and one twenty-sided die, and logs the results to the browser console. The `roll.js` module defines dice arrays and uses a shuffle function to randomly select values, exporting seven dice types (`d2` through `d20`). The HTML file contains only minimal styling and a script tag with `type="module"`, highlighting the modular import/export pattern without any visual output.

AI-generated description