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
// It will help to think about the order in which expressions are evaluated
9
9
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10
10
11
-
//console.log(num);
11
+
console.log(num);
12
12
13
13
//First operation
14
-
// num is generating a random floating number with method Math.random() between 0 and 1
14
+
// num is generating a random dicimal number with method Math.random() between 0 and 1 result eg :0.3948605
15
+
15
16
16
-
lettest=Math.random()
17
-
console.log(test)
18
17
19
18
//Second operation
20
-
//The generated number is multiplied by 100 being (maximum =100 -1 +1)
19
+
//The generated number is multiplied by the range+1 which is between 1-100 result eg 39.48605
21
20
22
-
test=test*(maximum-minimum+1);
23
-
console.log(test)
24
21
25
22
//Third operation
26
-
//num is rounded down to the nearset whole number using the method Math.floor
23
+
//num is rounded down to the nearset whole number using the method Math.floor restult eg 39.48605 => 39
24
+
27
25
28
-
test=test+minimum;
29
-
console.log("test+ minimum",test)
30
26
31
-
// Last operation is to add 1 to num 1 is stored in a variable called minimum
27
+
// Last operation is to add 1 to hit the maximum value (since Math.random() never quite reaches 1). This ensures all 100 numbers (1 through 100) are equally reachable.eg 39 => 40
0 commit comments