Skip to content

Commit 6ff1894

Browse files
committed
Completed exercise 4
1 parent 8e934c2 commit 6ff1894

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ 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+
// Math.random() generates a random decimal number between 0 and 1.
12+
// Since the minimum is 1 and maximum is 100 the bracket (maximum - minimum + 1) will always equal 100.
13+
// The random decimal number is then multiplied by 100, resulting in a random decimal number between 0 and 100.
14+
// Math.floor() then rounds this decimal number down to the nearest whole number.
15+
// Finally, the minimum value (1) is added
16+
// Resulting in a final value of num being a random whole number between 1 and 100.

0 commit comments

Comments
 (0)