Skip to content

Commit 14a8463

Browse files
committed
explained the expressions and what they do
1 parent 74df6bb commit 14a8463

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ 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+
// breaking down the expressions:
12+
// num is assigned the value of Math.floor(Math.random() * (maximum - minimum + 1)) + minimum
13+
// Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive)
14+
// (maximum - minimum + 1) calculates the range of possible values, which is 100 - 1 + 1 = 100
15+
// Math.random() * (maximum - minimum + 1) scales the random decimal to the range of possible values, resulting in a number between 0 and 100 (exclusive)
16+
// Math.floor() rounds down the scaled random number to the nearest whole number, giving us an integer between 0 and 99
17+
// Finally, adding minimum (which is 1) shifts the range from 0-99 to 1-100, resulting in num being a random integer between 1 and 100 (inclusive)
18+
console.log(num);

0 commit comments

Comments
 (0)