Skip to content

Commit 59481d1

Browse files
explain how it working
1 parent a9e44ee commit 59481d1

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

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

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

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
5+
console.log(`${num}`);
56

6-
// In this exercise, you will need to work out what num represents?
7-
// Try breaking down the expression and using documentation to explain what it means
8-
// It will help to think about the order in which expressions are evaluated
9-
// Try logging the value of num and running the program several times to build an idea of what the program is doing
7+
//num represents a random whole number between 1 and 100,
8+
//first we calculate value inside parentheses(maximum - minimum +1) = 100 -1 + 1 =100
9+
// math.random return number between 0 and 1
10+
// math.random() * 100 give us a integer number
11+
// math.floor round down the number
12+
// add 1 to the result
13+
//for example math.floor((0.783 *100))=78 + 1 = 79

0 commit comments

Comments
 (0)