Skip to content

Commit 20ea364

Browse files
committed
Add breakdown comments for Math.floor in 4-random.js
1 parent d93a91d commit 20ea364

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1616
// This expression can be simplified as (100 - 1 + 1), which equals 100. This tells the program how many possible whole numbers there are. There are 100 possibilities.
1717
// The +1 is important as without it, we would only reach 99 possibilities, that is 0 - 99.
1818
//-Math.random() * (maximum - minimum + 1):
19-
// This function multiplies the random fraction by the range size. Since Math.random() represents numbers >=0 and <1, this expression produces value anywhere from 0 up to 100, excluding 100.
20-
// Example to justify expression: 0.876 * 100 = 87.6
19+
// This function multiplies the random decimal by the range size. Since Math.random() represents numbers >=0 and <1, this expression produces value anywhere from 0 up to 100, excluding 100.
20+
// Example to justify expression: 0.876 * 100 = 87.6
21+
//-Math.floor: This static method rounds down to the nearest whole number, discarding the decimal. This turns the continuous range into whole numbers, from 0 - 99.
22+
// That is 87.6 becomes 87.

0 commit comments

Comments
 (0)