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
constminimum=1;// Sets the lowest possible number that can be generated
2
2
constmaximum=100;// Sets the highest possible number that can be generated
3
3
4
-
5
4
// In this exercise, you will need to work out what num represents?
6
5
// Try breaking down the expression and using documentation to explain what it means
7
6
// It will help to think about the order in which expressions are evaluated
8
7
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.
calculates the total number of possible values between minimum and maximum, (but not including) 100 (e.g., 0 to 99.999...).
21
+
22
+
4. Math.floor(...) — Function Call:
23
+
Rounds up the decimal to the nearest whole number, giving a whole number from 0 to 99.
12
24
13
-
2
14
-
// Math.random() returns a random decimal between 0 and 1
15
-
// Math.random() * maximum(100) returns a random decimal between 0 and 99.999
16
-
// Math.floor() rounds up the decimal to the nearest whole number
17
-
// maximum and minimum calculates thee total output of the number(100)
25
+
5. + minimum — Addition (Lowest Precedence):
26
+
Shifts the whole set of numbers up so that the lowest outcome becomes `minimum` (1) instead of 0, resulting in a whole number between 1 and 100 inclusive.
27
+
*/
18
28
19
29
// Try logging the value of num and running the program several times to build an idea of what the program is doing
20
30
21
-
console.log(num);// num represents a random whole number between 1 and 100
31
+
console.log(num);// num represents a random whole number between 1 and 100 inclusive
0 commit comments