Skip to content

Commit d39bec0

Browse files
committed
Explained evaluated how the expression works
1 parent 4c87f27 commit d39bec0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
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-
5+
console.log(num)
66
// In this exercise, you will need to work out what num represents?
77
// Try breaking down the expression and using documentation to explain what it means
88
// It will help to think about the order in which expressions are evaluated
99
// Try logging the value of num and running the program several times to build an idea of what the program is doing
10+
11+
// ANSWER
12+
// num represents a random whole number in the range 0 - 100.
13+
// math.random gives a random decimal between 0 and 1.math floor rounds the value to a whole number.
14+
// (maximum - minimum + 1) evaluates the total count of integers. (+ minimum )adds 1 to the outcome.
15+
// The code starts by evaluating math.random then multiply that by the maximum, math.floor will then round that value into a whole number then finally adding minimum to get num.

0 commit comments

Comments
 (0)