In This Chapter
Generating random numbers and integers
Working with conditions
Using the if-else and switch structures
Handling unusual conditions
One of the most important aspects of computers is their apparent ability to make decisions. Computers can change their behavior based on circumstances. In this chapter, you discover how to maximize this decision-making ability.
Math.random() function returns a random floating-point value between zero and one.
Creating a random floating-point number between zero and one is easy, thanks to the
Math.random() function. What if you want an integer within a specific range? For example, say that you want to simulate rolling a six-sided die. How do you get from the 0-to-1 floating-point value to a 1-to-6 integer?
Here's the standard approach:
Get a random float between ...