Skip to content

Commit a08fe81

Browse files
committed
explanation of what num represents
1 parent f0c63cb commit a08fe81

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ const minimum = 1;
22
const maximum = 100;
33

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
num = Math.floor(Math.random(0.9) * (100 - 1 + 1)) + 1;
56

67
// In this exercise, you will need to work out what num represents?
78
// Try breaking down the expression and using documentation to explain what it means
89
// It will help to think about the order in which expressions are evaluated
910
// Try logging the value of num and running the program several times to build an idea of what the program is doing
11+
//console.log(num)
12+
//output: random whole number
13+
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.
15+
16+
//example Math.random () = 0.97
17+
//0.97 * 100 = 97
18+
//Math.floor = 97
19+
//97+1 = 98

0 commit comments

Comments
 (0)