π Overview and Purpose
The Roll a Dice app offers a quick and easy way to generate a random number between 1 and 6, complete with engaging visual feedback. It is designed to be fully responsive and works perfectly across all modern browsers and devices (mobile, tablet, and desktop). Itβs ideal for settling disputes, playing casual games, or simply simulating probability.
β¨ Key Features
- Single D6 Roll: Generates a random integer result between 1 and 6 (inclusive).
- Visual Feedback: When the “Roll the Dice!” button is clicked, the dice face enters a ‘shaking’ animation for one second, providing a realistic visual simulation of a roll.
- Unicode Die Faces: The results are displayed using large, clear Unicode emoji die faces (β, β, β, β, β, β ) for instant recognition.
- Roll History Log: The app maintains a concise history of the last 10 rolls, displayed clearly beneath the roll button. This allows users to track recent results without needing to remember them.
- Clean User Interface (UI): Utilizes modern, responsive design principles for a pleasant user experience.
π² Dice Roller
1
Click the button to roll!
Latest Roll History
π οΈ Technology Stack
The application is built entirely using front-end web technologies combined into a single HTML file for maximum simplicity and portability:
- HTML5: Provides the foundational structure for the display screen, buttons, and history containers.
- CSS3 (via Tailwind CSS): The entire layout, spacing, colors, and responsive design are handled efficiently using Tailwind utility classes, ensuring a clean and modern aesthetic.
- Custom CSS: A small block of custom CSS is included specifically to define the
@keyframes shakeanimation, which gives the dice movement during the simulated roll. - JavaScript (ES6+): The core logic is handled by JavaScript, which performs three main tasks:
- Generates the random number (
Math.random()). - Controls the timing of the roll and the display of the animation (
setTimeout). - Manages the state of the application, including updating the main dice display and maintaining the
rollHistoryarray.
- Generates the random number (
π‘ How to Use Roll a Dice app
- Initial State: The die will initially display the ‘1’ face and the status message will prompt you to roll.
- Rolling: Click the “Roll the Dice!” button.
- Result: The button will temporarily change to “Rolling…”, the die will animate, and after a one-second delay, the final result (1-6) will appear.
- History: The new result is automatically added to the beginning of the “Latest Roll History” section.
