Skip to content

Commit aeabc99

Browse files
Add step-by-step explanation of Math.random, Math.floor, maximum, minimum, and num aand logged the value of num in my terminal
1 parent 14ba89d commit aeabc99

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
const minimum = 1;
2-
const maximum = 100;
1+
const minimum = 1; // Sets the lowest possible number that can be generated
2+
const maximum = 100; // Sets the highest possible number that can be generated
33

4-
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
54

65
// In this exercise, you will need to work out what num represents?
76
// Try breaking down the expression and using documentation to explain what it means
87
// It will help to think about the order in which expressions are evaluated
8+
9+
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
10+
// Math.random() returns a random decimal between 0 and 1
11+
// Math.random() * maximum(100) returns a random decimal between 0 and 99.999
12+
// Math.floor() rounds up the decimal to the nearest whole number
13+
// maximum and minimum calculates thee total output of the number(100)
14+
915
// Try logging the value of num and running the program several times to build an idea of what the program is doing
16+
17+
console.log(num); // num represents a random whole number between 1 and 100

0 commit comments

Comments
 (0)