Skip to content

Commit 14355ac

Browse files
committed
Done the answers for 4-random.js
Added // console.log(num); to be able to see code generation
1 parent 5f618f9 commit 14355ac

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

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

44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

6+
// console.log(num);
7+
68
// In this exercise, you will need to work out what num represents?
79
// Try breaking down the expression and using documentation to explain what it means
810
// It will help to think about the order in which expressions are evaluated
911
// Try logging the value of num and running the program several times to build an idea of what the program is doing
12+
/*
13+
Firstly its not running as it is showing as undefined as it is lacking something like console.log
14+
After adding console.log(num) and running it a few times I get 62, 45, 35, 10.
15+
For what it is doing: Math.floor is the sum of a random number from 0 to 0.9999... which is then multiplied by the maxium - minimun + 1, so 100 - 1 + 1.
16+
That gives a number from 0-99, then then adds the minimun which is 1, so that gives a random number from 1-100.
17+
*/

0 commit comments

Comments
 (0)