You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// In this exercise, you will need to work out what num represents?
7
9
// Try breaking down the expression and using documentation to explain what it means
8
10
// It will help to think about the order in which expressions are evaluated
9
11
// Try logging the value of num and running the program several times to build an idea of what the program is doing
12
+
13
+
// when first evaluating the full num expression i got the answer 99
14
+
// The second time i got 50 (which means .floor and .random are doing something to change the value of the expression each run)
15
+
16
+
// The order of operations is as follows:
17
+
18
+
// 1. The expression inside the parentheses is evaluated first: (maximum - minimum + 1) which gives us 100 - 1 + 1 = 100
19
+
// 2. Then Math.random() is called, which generates a random decimal number between 0 and 1.
20
+
// 3. The result of Math.random() is multiplied by the result of step 1, giving us a random decimal number between 0 and 100.
21
+
// 4. Math.floor() is then called on the result of step 3, which rounds it down to the nearest whole number, giving us a random integer between 0 and 99.
22
+
// 5. Finally, the minimum value (1) is added to the result of step 4, giving us a random integer between 1 and 100.
23
+
24
+
// When num = 99
25
+
// math.random gives us 0.98 (or something close to it)
26
+
// 0.98 * 100 = 98
27
+
// math.floor(98) = 98
28
+
// 98 + 1 = 99
29
+
30
+
// When num = 50
31
+
// math.random gives us 0.49 (or something close to it)
0 commit comments