File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,5 +10,18 @@ console.log(num);
1010// It will help to think about the order in which expressions are evaluated
1111// Try logging the value of num and running the program several times to build an idea of what the program is doing
1212// Breakdown of the expression
13- // 1. Math.random() this generates a decimal number from 0 up to , but not including 1
14- //num represents a random number between minimum and maximum
13+
14+ // The order is inner brackets first, multiplication, Math.floor and then + minimum
15+ // 1. maximum - minimum + 1 that is 100 - 1 + 1 = 100
16+ // This gives the total number of possible values (1 to 100 = 100)
17+
18+ // 2. Math.random() is a random decimal between 0 and 1 but not including 1 like 0.7392..
19+ // Math.random()*(maximum - minimum +1)
20+ // 0.7392 * 100 = 73.92
21+
22+ // 3. Math.floor(73.92) = 73 ,
23+ // it rounds down to the nearest whole number an integer from 0 to 99
24+
25+ // 4. + minimum will be 73 + 1 = 74
26+ // num represents random whole number between 1 and 100
27+
You can’t perform that action at this time.
0 commit comments