Skip to content

Commit 5e52076

Browse files
committed
Solved Exercise Math.floor and Math.random
1 parent 2d865ae commit 5e52076

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ 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+
/*
13+
The num is a variable that hold a random variable every time we run the code it gives us a different random number.
14+
In the above expression, firstly it will solve the parenthesis part i.e maximum - minimum +1.
15+
i.e, (100 - 1 +1)-> 100 then it will evaluate Math.random, Math.random generate any number from 0-1 and it will multiply by
16+
100 and added by minimum value i.e 1. Math.floor makes the value round if it is in decimal.
17+
*/

0 commit comments

Comments
 (0)