Skip to content

Commit de6389d

Browse files
committed
update: breaking down the expression and explain for clarity on random number generation in sprint -1 of 4-random.js
1 parent a7ffaa8 commit de6389d

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+
console.log(num);
11+
// Output: A random number between 1 and 100 (inclusive both 1 and 100)
12+
//num is a random number generated between the minimum 1 and maximum values 100.
13+
// The expression Math.random() generates a random floating-point number between [0,1).
14+
// The expression (maximum - minimum + 1) calculates the range of numbers we want to generate, which is 100 - 1 + 1 = 100.
15+
// The expression Math.floor() rounds down the result to the nearest whole number.
16+
// Finally, we add the minimum value to ensure that the random number falls within the desired range.

0 commit comments

Comments
 (0)