Skip to content

Commit e4c2e57

Browse files
committed
creating the dir and ext variables
1 parent af8a542 commit e4c2e57

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Sprint-1/1-key-exercises/2-initials.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ let firstName = "Creola";
22
let middleName = "Katherine";
33
let lastName = "Johnson";
44

5+
let initials =
6+
57
// Declare a variable called initials that stores the first character of each string.
68
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
79

8-
let initials = ``;
10+
let initials = `${firstName[C]}${middleName[K]}${lastName[J]}`;
911

1012
// https://www.google.com/search?q=get+first+character+of+string+mdn
1113

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
// The diagram below shows the different names for parts of a file path on a Unix operating system
2-
31
// ┌─────────────────────┬────────────┐
42
// │ dir │ base │
53
// ├──────┬ ├──────┬─────┤
64
// │ root │ │ name │ ext │
75
// " / home/user/dir / file .txt "
86
// └──────┴──────────────┴──────┴─────┘
97

10-
// (All spaces in the "" line should be ignored. They are purely for formatting.)
11-
128
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
13-
const lastSlashIndex = filePath.lastIndexOf("/");
14-
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
169

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
10+
// Find the index of the last slash and the last dot
11+
const lastSlashIndex = filePath.lastIndexOf("/");
12+
const lastDotIndex = filePath.lastIndexOf(".");
1913

20-
const dir = ;
21-
const ext = ;
14+
// Extract each part
15+
const base = filePath.slice(lastSlashIndex + 1); // "file.txt"
16+
const dir = filePath.slice(0, lastSlashIndex); // "/Users/mitch/cyf/Module-JS1/week-1/interpret"
17+
const ext = filePath.slice(lastDotIndex + 1); // "txt"
2218

23-
// https://www.google.com/search?q=slice+mdn
19+
console.log(`The dir part of ${filePath} is ${dir}`);
20+
console.log(`The base part of ${filePath} is ${base}`);
21+
console.log(`The ext part of ${filePath} is ${ext}`);

number-game-errors.html

Whitespace-only changes.

0 commit comments

Comments
 (0)