File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,8 +2,26 @@ const minimum = 1;
22const maximum = 100 ;
33
44const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
5+ console . log ( num )
6+
7+
8+ //In this exercise, you will need to work out what num represents?
9+ //Try breaking down the expression and using documentation to explain what it means
10+ //It will help to think about the order in which expressions are evaluated
11+ //Try logging the value of num and running the program several times to build an idea of what the program is doing
12+
13+ /*
14+ Answer
15+
16+ num is a variable that'll hold the output of the expression in line 4, I have run the code several times and I get a
17+ different number each run.
18+ Math.random returns a random decimal number between 0 (inclusive) and 1 (exclusive).
19+ Math.floor rounds the number to the nearest integer.
20+ This expression is evaluated according to parenthesis and operator precedence, so for this expression it will be as follows:
21+ 1. (maximum - minimum + 1)
22+ 2. Math.random() is called
23+ 3. result from Math.random * result from > maximum - minimum + 1
24+ 4. Math.floor is then called with (Math.random * result from > maximum - minimum + 1)
25+ 5. result from Math.floor + minimum
26+ */
527
6- // In this exercise, you will need to work out what num represents?
7- // Try breaking down the expression and using documentation to explain what it means
8- // It will help to think about the order in which expressions are evaluated
9- // Try logging the value of num and running the program several times to build an idea of what the program is doing
You can’t perform that action at this time.
0 commit comments