File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,3 +7,21 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77// Try breaking down the expression and using documentation to explain what it means
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
10+
11+ num //represents a random integer between the minimum value (1) and the maximum value (100).Math
12+
13+ ( maximum - minimum + 1 ) //represents the range of possible values, which is 100 - 1 + 1 = 100.
14+ // This means that there are 100 possible values that num can take on.
15+
16+ Math . random ( ) //generates a random decimal number between 0 and 1. This means that the value of Math.random()
17+ // can be any number between 0 and 1, but it will never be exactly 1.
18+
19+ Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) //multiplies the random decimal number generated by Math.random()
20+ // by the range of possible values (100), and then rounds down to the nearest integer using Math.floor().
21+ // This means that the result will be a random integer between 0 and 99.
22+
23+ Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum //adds the minimum value (1) to the result of the previous
24+ // expression. This means that the final result will be a random integer between 1 and 100, inclusive.
25+
26+
27+
You can’t perform that action at this time.
0 commit comments