Skip to content

Commit 50075e2

Browse files
Refine comments for clarity on random number generation logic
1 parent 2b99e8c commit 50075e2

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ const maximum = 100; // Sets the highest possible number that can be generated
66
// Try breaking down the expression and using documentation to explain what it means
77
// It will help to think about the order in which expressions are evaluated
88

9-
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // calculates the total count of all possible whole numbers between minimum and maximum.
9+
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // calculates the total number of possible values between minimum and maximum, inclusive.
10+
// Multiplying Math.random() by this total count of numbers gives a random float from 0 up to (but not including) that count.
11+
// Adding + minimum at the end shifts the whole set of numbers up so that the lowest possible value becomes minimum rather than 0.
12+
13+
2
1014
// Math.random() returns a random decimal between 0 and 1
1115
// Math.random() * maximum(100) returns a random decimal between 0 and 99.999
1216
// Math.floor() rounds up the decimal to the nearest whole number

0 commit comments

Comments
 (0)