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
Copy file name to clipboardExpand all lines: Sprint-1/1-key-exercises/4-random.js
+13-6Lines changed: 13 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,16 @@ console.log(num);
9
9
// It will help to think about the order in which expressions are evaluated
10
10
// Try logging the value of num and running the program several times to build an idea of what the program is doing
11
11
12
-
// Math.random() returns a random decimal number between 0 and 1
13
-
// (maximum - minimum + 1) represents the size of range of numbers we want to include. We add +1 because both minim and maximum are included in the range
14
-
// Math.random() * (maximum - minimum + 1) gives us a random decimal between 0 and 100, but still decimal
15
-
// Math.floor() rounds down to the nearest whole number. So this. turns decimals like 99.9 into 99
16
-
// + minimum since minimum = 1, this shifts the entire random range up by 1. so instead of 0-100, the range becomes 1-100
17
-
// num should return a random integer between 1 and 100
12
+
// Math.random() returns a random decimal in the interval [0, 1)
13
+
14
+
// (maximum - minimum + 1) gives the size of the interval [minimum, maximum]
15
+
16
+
// Math.random() * (maximum - minimum + 1)
17
+
// gives a random decimal in the interval [0, 100)
18
+
19
+
// Math.floor() rounds down to the nearest whole number
20
+
21
+
// + minimum shifts the interval upward by 1,
22
+
// so the final integer range becomes [1, 100]
23
+
24
+
// num should return a random integer between 1 and 100 inclusive
0 commit comments