File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,22 @@ const maximum = 100;
33
44const num = Math . floor ( Math . random ( ) * ( maximum - minimum + 1 ) ) + minimum ;
55
6+ console . log ( num ) ;
7+
68// In this exercise, you will need to work out what num represents?
9+
10+ // Answer: num is represents a random integer inclusive between minimum and maximum
11+
712// Try breaking down the expression and using documentation to explain what it means
813// It will help to think about the order in which expressions are evaluated
14+ // Answers: const minimum = 1 (thats's the minimum number constent variable)
15+ // const maxiumum = 100 (that's the maxiumum number constant variable)
16+ // Math.random: generates a random decimal number between 0 and 1
17+ // (maximum - minimum + 1) Calculates the range of possible numbers (100 - 1 + 1=100)
18+ // Math.random() * (maximum - minimum + 1) scales a random decimal to range a between 0 and 99.99
19+ // Math.floor: Rounds the decimal down to the nearest whole interger (0 to 99)
20+ // + minimum: shifts the range up by 1, resulting in the whole number from 1 to 100
21+
22+
923// Try logging the value of num and running the program several times to build an idea of what the program is doing
24+ // ran a console.log and the num value returned randomly each time
You can’t perform that action at this time.
0 commit comments