Skip to content

Commit 2dec0c8

Browse files
committed
explanation of num and expressions with comments and console.log
1 parent cabc767 commit 2dec0c8

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

Sprint-1/1-key-exercises/4-random.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
console.log(num);
12+
13+
// Math.floor()= rounds a number down to the nearest integer
14+
// Math.random() = generates a random float number between 0 and 1 (not including 1)
15+
// Math.random() * 100 = generates a random float number between 0 and 99.999...
16+
// (maximum - minimum + 1) -> scales the range of random numbers to be between the minimum and maximum values (including the maximum value)
17+
// + minimum -> shifts the range of random numbers to start from the minimum value instead of 0
18+
// So, the expression generates a random integer between the minimum and maximum values (inclusive)
19+
// num = a random integer between 1 and 100 (including 100)
20+

0 commit comments

Comments
 (0)