Skip to content

Commit a1bcfd7

Browse files
author
Payman IB
committed
4th completed and explained.
1 parent baf6383 commit a1bcfd7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sprint-1/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+
console.log(num);
12+
13+
// this will make a random number between 1-100. Math.random will give us a number between 0-1 (both ends included).
14+
// (maximum - minimum + 1): this is equal to 100-1+1=100 in this example.
15+
// (Math.random() * (maximum - minimum + 1)): this will multiply the random number which is between 0-1 by 100 so we have a number.
16+
// Math.floor: this will round the number to the nearest lower whole number.
17+
// + minimum: will add 1 (the defined minimum) to the number so it never be below 1.
18+
// so we end up with a random number between 1-100

0 commit comments

Comments
 (0)