Skip to content

Commit fd58796

Browse files
refactor: enhance comments for clarity on random number generation logic
1 parent fcff6a6 commit fd58796

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+
// This code generates a random number between 1 and 100, inclusive.
12+
// The Math.random() function generates a random floating-point number between 0 (inclusive) and 1 (exclusive).
13+
// The expression (maximum - minimum + 1) calculates the range of numbers we want to include.
14+
// By multiplying Math.random() by this range, we scale the random number to fit within the desired range.
15+
// The Math.floor() function rounds down the result to the nearest whole number.
16+
// Finally, we add the minimum value to ensure the result starts from the minimum value.

0 commit comments

Comments
 (0)