Skip to content

Commit d90d611

Browse files
committed
Fix: add error explanations and correct function call count
1 parent 98f2dbe commit d90d611

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
//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?
2+
//We don't want the computer to run these 2 lines - how can we solve this problem?
3+
4+
// Explanation:
5+
// Running this without comments gives a "SyntaxError".
6+
// This occurs because the computer tries to read plain English sentences as JavaScript code, which it cannot understand.
7+
// Adding '//' turns them into comments that the computer ignores.

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

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

33
let age = 33;
44
age = age + 1;
5+
6+
// Explanation:
7+
// The error is "TypeError: Assignment to constant variable."
8+
// This occurs because we used 'const' to declare the 'age' variable. 'const' creates a constant whose value cannot be reassigned after its initial creation.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
const cityOfBirth = "Bolton";
44
console.log(`I was born in ${cityOfBirth}`);
55

6+
// Explanation:
7+
// The error is "ReferenceError: Cannot access 'cityOfBirth' before initialization."
8+
// JavaScript executes code from top to bottom. We tried to print 'cityOfBirth' before we actually declared and initialized it on the next line.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ console.log(last4Digits);
77
// Then run the code and see what error it gives.
88
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
11+
// Explanation:
12+
// The error is "TypeError: cardNumber.slice is not a function."
13+
// This occurs because the original cardNumber was a Number type. The '.slice()' method only works on Strings and Arrays, not on pure numbers.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ const time12Hour = "20:53";
22
const time24Hour = "08:53";
33

44
console.log(time12Hour);
5-
console.log(time24Hour);
5+
console.log(time24Hour);
6+
7+
// Explanation:
8+
// The error is a "SyntaxError".
9+
// This occurs because it violates JavaScript naming conventions: variable names cannot start with a number.

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ console.log(`The percentage change is ${percentageChange}`);
1212
// Read the code and then answer the questions below
1313

1414
// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
// Answer: There are 5 function calls in total. They are located on lines 4, 5, and 10.
15+
// Answer: There are 2 function calls in total. They are both `Number()` and are located on lines 4 and 5.
1616
// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
1717
// Answer: The error comes from line 5. It occurs because we are trying to reassign a value to `priceAfterOneYear`, which was originally declared as a `const`. To fix it, change `const` to `let` on line 2.
1818
// c) Identify all the lines that are variable reassignment statements

0 commit comments

Comments
 (0)