Skip to content

Commit 2309db3

Browse files
committed
completed random.js with comments
1 parent ed76a69 commit 2309db3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Sprint-1/1-key-exercises/3-paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ console.log(`The base part of ${filePath} is ${base}`);
1818
// Create a variable to store the ext part of the variable
1919

2020
//Answer:
21-
//**where the file lives^^
21+
//**where the file lives**
2222
// It gives me everything from Index 0 to
2323
// the last slash just before the filename.
2424
const dir = filePath.slice(0, lastSlashIndex);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ const maximum = 100;
44
const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
55

66
// In this exercise, you will need to work out what num represents?
7+
//*Answer:
8+
//Number returns a random whole number between 1 and 100.
9+
710
// Try breaking down the expression and using documentation to explain what it means
11+
/*Answer:
12+
It uses 2 methods to achieve this
13+
Math.random generate a random number between 0 and 1 eg. 0.343, 0.5. 0.67
14+
Math.floor rounds the number to a whole number.
15+
In this declaration:
16+
Math.random will return a random decimal number and multiplies it by the sum of
17+
((maximum-minimum)+1). eg 0.343_*((100-1)+1) = 34.3.
18+
Math.floor will take the total 34.3 and round it to a whole number 34*/
19+
820
// It will help to think about the order in which expressions are evaluated
21+
//*Answer:
22+
//it first works out the random decimal number calculates the other values then evaluates to sum to a whole number.
23+
924
// Try logging the value of num and running the program several times to build an idea of what the program is doing
25+
//*Answer:
26+
//28, 64, 52, 86

0 commit comments

Comments
 (0)