Skip to content

Commit cada88b

Browse files
committed
added an explaination of the code and what is actually does.
1 parent 076088c commit cada88b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ num = Math.floor(Math.random() * (maximum - minimum) + 1);
99
// Try breaking down the expression and using documentation to explain what it means
1010
// It will help to think about the order in which expressions are evaluated
1111
// Try logging the value of num and running the program several times to build an idea of what the program is doing
12+
13+
// 1. const minimum = 1; : a variable has the name `minimum` declared. it stores hte 1 value. `const` means this var is unchangeable.
14+
// 2. const maximum = 100; a variable has the name `maximum` declared. it stores hte 100 value. `const` means this var is unchangeable.
15+
// 4. num = Math.floor(Math.random() * (maximum - minimum) + 1); : in this line, the variable `num` is declared, it stores a random number
16+
// between 1 and 100. Math.random() generates a random decimal number between 0 and 1 (exclusive).
17+
// then it multiplies this random number by (maximum - minimum) to scales it to a range between 0 and 99 (since maximum is 100 and minimum is 1).
18+
// Adding 1 shifts this range to be between 1 and 100.
19+
// Math.floor() then rounds down the result number to the nearest whole number, and ensures that num is an integer between 1 and 100.
20+
21+
// So the whole code generates a random integer between 1 and 100 (inclusive) and stores it in the variable num.

0 commit comments

Comments
 (0)