Skip to content

Commit fb41b78

Browse files
committed
Answer to 4-random.js included as text
1 parent 9fe6f44 commit fb41b78

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ const maximum = 100;
33

44

55
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
6+
console.log(num);
67

78

89

910
// In this exercise, you will need to work out what num represents?
1011
// Try breaking down the expression and using documentation to explain what it means
1112
// It will help to think about the order in which expressions are evaluated
1213
// Try logging the value of num and running the program several times to build an idea of what the program is doing
14+
15+
//Num generates a random number 0-0.9999999999999999, then multiplies it by (100-1+1=100), which gives a number between 0 and 99.99999999999999. Then it adds 1, which gives a number between 1 and 100. Finally, it uses Math.floor to round down to the nearest whole number, giving a final result of a random integer between 1 and 100 (inclusive).

0 commit comments

Comments
 (0)