Skip to content

Commit 2de6944

Browse files
committed
added clearer description of variable num
1 parent 2886191 commit 2de6944

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ const maximum = 100;
33

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

6-
76
// In this exercise, you will need to work out what num represents?
87
// Try breaking down the expression and using documentation to explain what it means
98
// It will help to think about the order in which expressions are evaluated
109
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1110
//console.log(num)
1211
//output: random whole number
1312

14-
// So num is storing the value of a random number generated by the method Math.random this will be a number between zero and one that is then multiplied by 100 (100(maximum) -1(minimum) +1) and then whatever this number is, one is added on to that number and then finally the Math.floor method will round that number down to the nearest whole number add one and this final number is what is stored in the variable num.
13+
//So num is storing the value of a random number generated by the method Math.random this will be a decimal number between zero and one that is then multiplied by 100 (100(maximum) -1(minimum) +1) and then the Math.floor method will round that number down to the nearest whole number and then finally whatever this number is, one is added on to that number and this final number is what is stored in the variable num. This final number is what is stored in the variable num. The smallest value it can be is 1, and the largest value it can be is 100 as plus minimum means 1 will always be added.
1514

1615
//example Math.random () = 0.97
1716
//0.97 * 100 = 97

0 commit comments

Comments
 (0)