Skip to content

Commit bf72972

Browse files
committed
4-random added answer with //
1 parent 94908cd commit bf72972

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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

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

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
console.log (num);
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+
12+
// From what I can work out, it is generations a random number between 2 and 100 for the value of num.
13+
// math.floor ensures the number is a whole number without decibils. (maximum - minimu +1) is (100 - 1 + 1)=100.
14+
// Math.random pics a random number from 0 to 1 with two decibils, such as 2.13.
15+
// The Order they follow is: Match.random multiplied by (Maximum - minimum + 1), then add minimum of 1.

0 commit comments

Comments
 (0)