Skip to content

Commit dd868f0

Browse files
author
Diana Ausiejute
committed
Finished the first 4 key exercises
1 parent 22f5729 commit dd868f0

7 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎Sprint-2/1-key-exercises/1-count.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ count = count + 1;
44

55
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66
// Describe what line 3 is doing, in particular focus on what = is doing
7+
8+
9+
// "=" is an assignment operator and so what line 3 is doing, is the new value is being assigned to the variable "count", which in this case is an expression

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const lastName = "Johnson";
55
// Declare a variable called initials that stores the first character of each string.
66
// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution.
77

8-
const initials = ``;
8+
let initials = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0);
9+
10+
911

1012
// https://www.google.com/search?q=get+first+character+of+string+mdn
13+
14+
console.log(initials);

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt";
1313
const lastSlashIndex = filePath.lastIndexOf("/");
1414
const base = filePath.slice(lastSlashIndex + 1);
15-
console.log(`The base part of ${filePath} is ${base}`);
15+
//console.log(`The base part of ${filePath} is ${base}`);
1616

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 = ;
2220

23-
// https://www.google.com/search?q=slice+mdn
21+
// https://www.google.com/search?q=slice+mdn
22+
23+
const lastDotIndex = filePath.lastIndexOf(".");
24+
const ext = filePath.slice(lastDotIndex + 1);
25+
26+
27+
28+
//const firstSlashIndex = filePath.indexOf("/");
29+
//const dir = filePath.slice(firstSlashIndex + lastSlashIndex);
30+
//const dir = filePath.slice(0 + lastSlashIndex);
31+
//const dir = filePath.slice(0 + (lastSlashIndex - 1));
32+
//const dir = filePath.slice(0 + (lastSlashIndex - 44));
33+
const dir = filePath.slice(0, lastSlashIndex + 1);
34+
35+
36+
console.log(dir)
37+

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ 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+
12+
console.log(num);
13+
// This expression uses 2 methods in order to create a random number between (min)1 and (max)100

‎Sprint-2/2-mandatory-errors/0.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
This is just an instruction for the first activity - but it is just for human consumption
2-
We don't want the computer to run these 2 lines - how can we solve this problem?
1+
// This is just an instruction for the first activity - but it is just for human consumption
2+
// We don't want the computer to run these 2 lines - how can we solve this problem?

‎Sprint-2/2-mandatory-errors/1.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
const age = 33;
44
age = age + 1;
5+
6+
// the error is in line 4. It's a "TypeError: Assignment to constant variable", which happened because the value to
7+
// a constant can only be assigned once (as it's )

‎Sprint-2/2-mandatory-errors/2.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
// an error in line 4, "ReferenceError: Cannot access 'cityOfBirth' before initialization", which proves my assumption that
8+
// the value of cityOfBirth should have been assigned prior to trying to print the string

0 commit comments

Comments
 (0)