Skip to content

Commit b59a3a9

Browse files
authored
Update 4-random.js
1 parent 0ca0cc5 commit b59a3a9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
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+
//ANSWER
12+
// const minimum = 1 sets the minimum value to 1
13+
// const maximum = 100 sets the maximum value to 100
14+
//Math.random() generates a random decimal number, zero inclusive but not 1.
15+
// (maximum - minimum + 1) calculates how many whole numbers maximum and minimum
16+
// Math.random() * (maximum - minimum + 1) ensures that the random decimal is within the desired range.
17+
// Math.floor(...) rounds the number down to the nearest whole integer
18+
// + minimum shifts the range upward so it starts at minimum instead of 0
19+
// The program generated random numbers from 0 to 100 as whole integers.

0 commit comments

Comments
 (0)