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
Copy file name to clipboardExpand all lines: Sprint-1/1-key-exercises/1-count.js
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,5 +2,12 @@ let count = 0;
2
2
3
3
count=count+1;
4
4
5
+
console.log(count);// should print 1
6
+
5
7
// Line 1 is a variable declaration, creating the count variable with an initial value of 0
6
8
// Describe what line 3 is doing, in particular focus on what = is doing
9
+
10
+
11
+
// On line 3, the code `count = count + 1;` updates the value of the variable `count`. JavaScript first takes the current value stored in `count`, adds `1` to it, and then assigns the new result back into the same variable.
12
+
// The `=` symbol here is the **assignment operator**. It does not mean “equals” in mathematics. Instead, it means “take the value on the right-hand side and store it in the variable on the left-hand side.”
13
+
// After this line runs, `count` now contains the value `1` instead of `0`.
Copy file name to clipboardExpand all lines: Sprint-1/1-key-exercises/3-paths.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,10 @@ console.log(`The base part of ${filePath} is ${base}`);
17
17
// Create a variable to store the dir part of the filePath variable
18
18
// Create a variable to store the ext part of the variable
19
19
20
-
constdir=;
21
-
constext=;
20
+
constdir=filePath.slice(0,lastSlashIndex);// dir part is "/Users/mitch/cyf/Module-JS1/week-1/interpret"
21
+
constext=base.slice(base.lastIndexOf("."));// ext part is ".txt"
22
+
23
+
console.log(`The dir part of ${filePath} is ${dir}`);// print: The dir part of /Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt is /Users/mitch/cyf/Module-JS1/week-1/interpret
24
+
console.log(`The ext part of ${filePath} is ${ext}`);// print: The ext part of /Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt is .txt
// The last4Digits variable should store the last 4 digits of cardNumber
5
7
// However, the code isn't working
6
8
// Before running the code, make and explain a prediction about why the code won't work
7
9
// Then run the code and see what error it gives.
8
10
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
9
11
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
12
+
13
+
14
+
// Before running the code, I predicted: The code will throw an error because cardNumber is defined as a number (not a string), and numbers don't have a .slice() method.
15
+
// The .slice() method is only available on strings and arrays, not on number primitives
16
+
// To fix the code, we need to convert the number to a string first, then use .slice()
0 commit comments