Skip to content

Commit 519042c

Browse files
completed_random.js
1 parent 697d88c commit 519042c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ 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+
// First, maximum - minimum + 1 is calculated, so 100 - 1 + 1 equals 100.
12+
// Then, a random fractional number between 0 and 1 is chosen(except 1), for example 0.3.
13+
// Next, Math.random() * 100 gives 30.
14+
// Math.floor rounds this number down to the nearest integer, and the final step adds 1, giving 31.

0 commit comments

Comments
 (0)