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-2/1-key-exercises/4-random.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,11 @@ const maximum = 100; // Sets the highest possible number that can be generated
6
6
// Try breaking down the expression and using documentation to explain what it means
7
7
// It will help to think about the order in which expressions are evaluated
8
8
9
-
constnum=Math.floor(Math.random()*(maximum-minimum+1))+minimum;// calculates the total count of all possible whole numbers between minimum and maximum.
9
+
constnum=Math.floor(Math.random()*(maximum-minimum+1))+minimum;// calculates the total number of possible values between minimum and maximum, inclusive.
10
+
// Multiplying Math.random() by this total count of numbers gives a random float from 0 up to (but not including) that count.
11
+
// Adding + minimum at the end shifts the whole set of numbers up so that the lowest possible value becomes minimum rather than 0.
12
+
13
+
2
10
14
// Math.random() returns a random decimal between 0 and 1
11
15
// Math.random() * maximum(100) returns a random decimal between 0 and 99.999
12
16
// Math.floor() rounds up the decimal to the nearest whole number
0 commit comments