Skip to content

Commit 63c562a

Browse files
committed
Improve documentation clarity by adding inline comments to expressions in random number generation
1 parent 688f25b commit 63c562a

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77

88
// Try breaking down the expression and using documentation to explain what it means
99

10-
The expression Math.floor() rounds a number down to the nearest integer.
11-
The expression Math.random() generates a random floating-point number between 0 and 1.
12-
The expression (maximum - minimum + 1) calculates the range of numbers between the minimum and maximum values.
13-
The expression Math.random() * (maximum - minimum + 1) generates a random floating-point number between 0 and the range of numbers.
14-
The expression Math.floor(Math.random() * (maximum - minimum + 1)) rounds that random number down to the nearest integer, resulting in a random integer between 0 and the range of numbers.
15-
Finally, adding minimum to that result shifts the range to be between the minimum and maximum values.
10+
The expression Math.floor() //rounds a number down to the nearest integer.
11+
The expression Math.random() //generates a random floating-point number between 0 and 1.
12+
The expression (maximum - minimum + 1) //calculates the range of numbers between the minimum and maximum values.
13+
The expression Math.random() * (maximum - minimum + 1) //generates a random floating-point number between 0 and the range of numbers.
14+
The expression Math.floor(Math.random() * (maximum - minimum + 1)) //rounds that random number down to the nearest integer, resulting in a random integer between 0 and the range of numbers.
15+
Finally, adding minimum to that result //shifts the range to be between the minimum and maximum values.
1616
// It will help to think about the order in which expressions are evaluated
1717
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1818

0 commit comments

Comments
 (0)