Skip to content

Commit ed68c8b

Browse files
committed
fix: used precise interval notation [0, 1) in Math.random comment
1 parent f711afc commit ed68c8b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Ge
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
1010

11-
// Generate a random decimal number between 0 and 1
11+
// Generates a random decimal number in the interval [0, 1)
12+
// (includes 0, excludes 1)
13+
// MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
1214
const decimal = Math.random();
13-
// Calculate the range size
15+
// Calculates the range size
1416
const range = maximum - minimum + 1;
15-
// Scale the decimal to the range
17+
// Scales the decimal to the range
1618
const scaled = decimal * range;
17-
// Round down to get a whole number
19+
// Rounds down to get a whole number
1820
const floored = Math.floor(scaled);
19-
// Shift the number up to start at the minimum
21+
// Shifts the number up to start at the minimum
2022
const result = floored + minimum;
21-
// Log each part to understand the process
23+
// Logs each part to understand the process
2224
console.log("decimal:", decimal);
2325
console.log("range:", range);
2426
console.log("scaled:", scaled);

0 commit comments

Comments
 (0)