File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 11const minimum = 1 ;
22const maximum = 100 ;
33
4- const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
4+ const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
5+ console . log ( num ) ;
6+
57
68// In this exercise, you will need to work out what num represents?
79// Try breaking down the expression and using documentation to explain what it means
810// It will help to think about the order in which expressions are evaluated
911// Try logging the value of num and running the program several times to build an idea of what the program is doing
12+
13+ // Breaking down what num represents:
14+ // num generates a random integer between 1 and 100 (inclusive)
15+
16+ // Step-by-step evaluation:
17+ // 1. Math.random() → generates a decimal between 0 (inclusive) and 1 (exclusive)
18+ // 2. (maximum - minimum + 1) → calculates the range size: (100 - 1 + 1) = 100
19+ // 3. Math.random() * 100 → gives a decimal between 0 and 99.999...
20+ // 4. Math.floor(...) → rounds down to get integers from 0 to 99
21+ // 5. + minimum → shifts the range from 0-99 to 1-100
22+
23+ // So num represents a random integer from 1 to 100
You can’t perform that action at this time.
0 commit comments