Skip to content

Commit d93a91d

Browse files
committed
Add additional breakdown comments in 4-random.js
1 parent de4738f commit d93a91d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1111
//Solution
1212
//- "num" represents a random whole number between 1 and 100.
1313
//Break down of expression
14-
//-Math.random: This generates a random decimal number between 0 and 1. It can return 0, but never reaches 1. (Example: 0.87).
14+
//-Math.random: This generates a random decimal number between 0 and 1. It can return 0, but never reaches 1. (Example: 0.876).
1515
//-(maximum - minimum + 1):
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.
17-
// The +1 is important as without it, we would only reach 99 possibilities, that is 0 - 99.
17+
// The +1 is important as without it, we would only reach 99 possibilities, that is 0 - 99.
18+
//-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

0 commit comments

Comments
 (0)