File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,17 @@ const maximum = 100;
44const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
55
66// In this exercise, you will need to work out what num represents?
7+
78// Try breaking down the expression and using documentation to explain what it means
9+
10+ The expression Math . floor ( ) rounds a number down to the nearest integer .
11+ The expression Math . random ( ) generates a random floating - point number between 0 and 1.
12+ The expression ( maximum - minimum + 1 ) calculates the range of numbers between the minimum and maximum values .
13+ The expression Math . random ( ) * ( maximum - minimum + 1 ) generates a random floating - point number between 0 and the range of numbers .
14+ The expression Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) rounds that random number down to the nearest integer , resulting in a random integer between 0 and the range of numbers .
15+ Finally , adding minimum to that result shifts the range to be between the minimum and maximum values .
816// It will help to think about the order in which expressions are evaluated
917// Try logging the value of num and running the program several times to build an idea of what the program is doing
18+
19+ console . log ( num ) ;
20+
You can’t perform that action at this time.
0 commit comments