Skip to content

Commit 492c04f

Browse files
committed
Solved 4-random.js
1 parent 1473a63 commit 492c04f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,22 @@ 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+
console.log(`Random number between ${minimum} and ${maximum}: ${num}`);
12+
13+
console.log(
14+
"Random number between 0 and 1 after evaluating Math.random() is: ",
15+
Math.random()
16+
);
17+
console.log(
18+
"Math.random() * (maximum - minimum + 1) scales the range from 1 to 100 (100 isn't included) for the random number: ",
19+
Math.random() * (maximum - minimum + 1)
20+
);
21+
console.log(
22+
"Math.floor(Math.random() * (maximum - minimum + 1)) rounds down the random number: ",
23+
Math.floor(Math.random() * (maximum - minimum + 1))
24+
);
25+
console.log(
26+
"(Math.floor(Math.random() * (maximum - minimum + 1)) + minimum) shifts the range to 1–100 (100 is included): ",
27+
Math.floor(Math.random() * (maximum - minimum + 1)) + minimum
28+
);

0 commit comments

Comments
 (0)