Chapter 6. Rolling Dice

Traditional board games such as Ludo, Monopoly, and Snake & Ladders all have an element of chance. Success is sometimes based solely on luck and the roll of the dice. In this chapter, you’ll create a JavaScript module that mimics a six-sided die (the standard die that comes with most board games). You’ll reuse this module in later chapters to give random greetings to players who join the game.

In this chapter, I’ll walk you through creating your first reusable JavaScript module.

Randomness

When you throw a six-sided die, there’s no way of knowing what the throw will be; it can be any number between 1 and 6, but it’s impossible to know ahead of time. The number thrown is said to be random. Computers can also provide random ...

Get A Beginner’s Guide to Writing Minecraft Plugins in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.