Skip to content

Commit 46a401b

Browse files
committed
documented the evaluation of the code provided in 4-random.js file
1 parent 089f7cf commit 46a401b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
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+
12+
/*
13+
num stores a random integer between minimum (1) and maximum (100), inclusive.
14+
15+
Breakdown:
16+
1. Math.random() generates a decimal number between 0 (inclusive) and 1 (exclusive).
17+
2. Multiplying by (maximum - minimum + 1) scales the range to 0–100.
18+
3. Math.floor() removes the decimal part, producing integers from 0–99.
19+
4. Adding minimum shifts the range to 1–100.
20+
*/
21+
console.log(num);

0 commit comments

Comments
 (0)