Skip to content

Commit 58524cd

Browse files
committed
Sprint 1 exercises: complete 4-random.js with explanation
1 parent df378aa commit 58524cd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

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

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

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
6+
console.log(num);
7+
8+
// num is a random integer between 1 and 100 (inclusive).
9+
// Math.random() returns a decimal in the range [0, 1).
10+
// Multiplying by (maximum - minimum + 1) scales it to the size of the range.
11+
// Math.floor(...) converts it to an integer.
12+
// Adding minimum shifts the range to start at 1 instead of 0.

0 commit comments

Comments
 (0)