@@ -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
1214const decimal = Math . random ( ) ;
13- // Calculate the range size
15+ // Calculates the range size
1416const range = maximum - minimum + 1 ;
15- // Scale the decimal to the range
17+ // Scales the decimal to the range
1618const scaled = decimal * range ;
17- // Round down to get a whole number
19+ // Rounds down to get a whole number
1820const floored = Math . floor ( scaled ) ;
19- // Shift the number up to start at the minimum
21+ // Shifts the number up to start at the minimum
2022const result = floored + minimum ;
21- // Log each part to understand the process
23+ // Logs each part to understand the process
2224console . log ( "decimal:" , decimal ) ;
2325console . log ( "range:" , range ) ;
2426console . log ( "scaled:" , scaled ) ;
0 commit comments