Skip to content

Commit 1b2d588

Browse files
committed
Added explanation comments for random number generation logic
1 parent 5c2bec5 commit 1b2d588

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ 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() returns a random number between 0 and 1 but not including 1. By multiplying by (maximum-minimum +1) we get a random number between 0 and 100.
12+
// The answer could however be in decimal point, thereofor by using Math.floor() we round down to the nearest whole number, but that would give us a range between 0 and 99. Adding minimum (1) to the result gives us a range between 1 and 100 inclusive.

0 commit comments

Comments
 (0)