Skip to content

Commit bf6881c

Browse files
committed
finished key exercises
1 parent e200504 commit bf6881c

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,30 @@
1010
// (All spaces in the "" line should be ignored. They are purely for formatting.)
1111

1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13+
14+
// Find the last slash and we can seperate the base from "dir"
1315
const lastSlashIndex = filePath.lastIndexOf("/");
1416
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
1617

17-
// Create a variable to store the dir part of the filePath variable
18-
// Create a variable to store the ext part of the variable
18+
// Find the last dot
19+
const lastDot = base.lastIndexOf(".");
20+
// console.log(`The base part of ${filePath} is ${base}`);
21+
22+
// Ectract everything before the base
23+
const dir = filePath.slice(0, lastSlashIndex);
24+
// Extract the txt extention from the dot
25+
const ext = base.slice(lastDot);
26+
27+
28+
1929

20-
const dir = ;
21-
const ext = ;
2230

23-
// https://www.google.com/search?q=slice+mdn
31+
32+
33+
34+
35+
36+
// Create a variable to store the dir part of the filePath variable
37+
// Create a variable to store the ext part of the variable
38+
console.log(`The base part of ${filePath} is ${base}`);
39+
// Moved to bottom its confusing me

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ 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+
// Answer: Inermost brackets first (maximum - minimum + 1) this is calcuating the range
12+
// Math.random generated a number between 0 and 1 but wont get to 1
13+
// Math.random * 100 moved the comma by 2 decimal places
14+
// Math.floor wii remove decimal parts of the number
15+
// + minimum will add 1
16+
17+
console.log(num);

0 commit comments

Comments
 (0)