Skip to content

Commit 7ca09e8

Browse files
committed
Explain num and expression
1 parent fc7d149 commit 7ca09e8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
//num is a random, rounded down number between 100 and 1.
12+
//math.floor rounds down.
13+
//math.random gives a random number between 0 and 1. It can be equal to 0, but not equal to 1,
14+
//(maximum - minimum + 1) gives in this case 100
15+
//So then Math.random() * (maximum - minimum + 1) gives a number between 0 and 99
16+
//Math.random() * (maximum - minimum + 1) gives a number between 1 and 100
17+
//and thus Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; gives a whole rounded
18+
//down number

0 commit comments

Comments
 (0)