Skip to content

Commit 42991c0

Browse files
committed
expand breakdown of random expression in sprint 2 exercise 4
1 parent 3e7fa88 commit 42991c0

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,18 @@ console.log(num);
1010
// It will help to think about the order in which expressions are evaluated
1111
// Try logging the value of num and running the program several times to build an idea of what the program is doing
1212
// Breakdown of the expression
13-
// 1. Math.random() this generates a decimal number from 0 up to , but not including 1
14-
//num represents a random number between minimum and maximum
13+
14+
// The order is inner brackets first, multiplication, Math.floor and then + minimum
15+
// 1. maximum - minimum + 1 that is 100 - 1 + 1 = 100
16+
// This gives the total number of possible values (1 to 100 = 100)
17+
18+
// 2. Math.random() is a random decimal between 0 and 1 but not including 1 like 0.7392..
19+
// Math.random()*(maximum - minimum +1)
20+
// 0.7392 * 100 = 73.92
21+
22+
// 3. Math.floor(73.92) = 73 ,
23+
// it rounds down to the nearest whole number an integer from 0 to 99
24+
25+
// 4. + minimum will be 73 + 1 = 74
26+
// num represents random whole number between 1 and 100
27+

0 commit comments

Comments
 (0)