Skip to content

Commit a364709

Browse files
committed
Explain math.floor
1 parent 4e28617 commit a364709

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
1010
console.log(num);
1111
// num is a random whole number between minimum and maximum.
1212
// Math.random() returns a number that's greater than or equal to 0 and less than 1.
13-
/*Then we multiply by (maximum - minimum + 1) to get a range of possible values, which means
14-
all the values num could end up being. In this program, num can be any whole number from 1 to 100, inclusive
15-
so both 1 and 100 are possible.*/
16-
// Math.floor(...) turns that into a whole number.
17-
// Finally, we add minimum so the number starts at minimum instead of 0.
13+
// Multiplying by 100 gives a value from 0 (inclusive) up to 100 (exclusive).
14+
// Math.floor(...) makes that an integer from 0 to 99.
15+
// Adding minimum (1) shifts the result to an integer from 1 to 100, inclusive.

0 commit comments

Comments
 (0)