Skip to content

Commit a04165e

Browse files
committed
Explain random number expressions
1 parent bccc1dd commit a04165e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎Sprint-2/1-key-exercises/4-random.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ console.log(num);
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
// 1. Math.random() produces a random decimal number in the range [0, 1).
12+
// 0 is included, but 1 is not included.
13+
14+
// 2. Math.random() * (maximum - minimum + 1) produces a random decimal
15+
// number in the range [0, 100), because maximum - minimum + 1 = 100.
16+
17+
// 3. Math.floor(Math.random() * (maximum - minimum + 1)) rounds the
18+
// decimal number down and produces a random whole number from 0 to 99.
19+
20+
// 4. Math.floor(Math.random() * (maximum - minimum + 1)) + minimum
21+
// adds 1 to the result, producing a random whole number from 1 to 100.

0 commit comments

Comments
 (0)