Skip to content

Commit a66e3fe

Browse files
committed
completed paths.js with added comments
1 parent db7592c commit a66e3fe

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ console.log(`The base part of ${filePath} is ${base}`);
1717
// Create a variable to store the dir part of the filePath variable
1818
// Create a variable to store the ext part of the variable
1919

20-
const dir = ;
21-
const ext = ;
20+
//Answer:
21+
//**where the file lives^^
22+
// It gives me everything from Index 0 to
23+
// the last slash just before the filename.
24+
const dir = filePath.slice(0, lastSlashIndex);
25+
console.log(dir);
26+
27+
//Answer:
28+
//**what type of file**
29+
//Uses the the lastIndexOf method to look for the dot.
30+
//the dot is now index 0 so we start from index 1 onwards
31+
// to get the file type.
32+
const ext = filePath.slice(filePath.lastIndexOf(".") + 1);
33+
console.log(ext);
2234

2335
// https://www.google.com/search?q=slice+mdn

0 commit comments

Comments
 (0)