You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system
37
+
//const base = filePath.slice(lastSlashIndex + 1);
38
+
// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method
39
+
//console.log(`The base part of ${filePath} is ${base}`);
40
+
// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension
16
41
17
42
// Create a variable to store the dir part of the filePath variable
18
43
// Create a variable to store the ext part of the variable
19
44
20
-
constdir=;
21
-
constext=;
45
+
constlastSlashIndex=filePath.lastIndexOf("/");
46
+
// here we have the variable lastslashIndex already created and identified its position
47
+
// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base
48
+
constdir=filePath.slice(0,lastSlashIndex);
49
+
console.log(dir);
50
+
// we show our result in the console
51
+
constlastDotIndex=filePath.lastIndexOf('.');
52
+
// we create a variable and assign its value using the indexOf to be from the dot location
53
+
constext=filePath.slice(lastDotIndex);
54
+
// we create a variable where we assign its value using the slice method to be from the dot only
22
55
23
-
// https://www.google.com/search?q=slice+mdn
56
+
console.log(ext)
57
+
// we print our result in the console
58
+
//slice(startIndex, endIndex)
59
+
// means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method,
60
+
// my comments needs correcting to look profissional -_-
Copy file name to clipboardExpand all lines: Sprint-2/2-mandatory-errors/2.js
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3,3 +3,5 @@
3
3
4
4
console.log(`I was born in ${cityOfBirth}`);
5
5
constcityOfBirth="Bolton";
6
+
7
+
// the variable was declared after the print function so the program doesn't know what is cityofBirth. Therefore it can't perform the print function or excuted before declaring the variable
0 commit comments