Skip to content

Commit 2d32e8e

Browse files
committed
comment errors in 2-mandatory-errors JavaScript files
1 parent 81bacc5 commit 2d32e8e

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ We don't want the computer to run these 2 lines - how can we solve this problem?
66
// ^^
77

88
// SyntaxError: Unexpected identifier 'is'
9-
//this points to the error being "is" which is believed to be an unexpected identifier. This is bc the comment was not commented out, so the first word was thought the be an identifier, but then the next word also, which did not make sense, so that is what the error msg flagged up. it dod not go further, as it ran into issues on the second word.
9+
//this points to the error being "is" which is believed to be an unexpected identifier. This is because the comment was not commented out, so the first word was interpreted as an identifier, but then the next word also, which did not make sense. It did not go further, as it ran into issues on the second word.

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

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
//ReferenceError: Cannot access 'cityOfBirth' before initialization
8+
//this occurred because the variable 'cityOfBirth' was accessed on line 4, but before line 5 - where it was initialised.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = Number(String(cardNumber).slice(-4));
33

44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
66
// Before running the code, make and explain a prediction about why the code won't work
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+
/* It will throw an error as .slice() is a string and array method, I don't think it works on numbers.
12+
13+
const last4Digits = cardNumber.slice(-4);
14+
^
15+
TypeError: cardNumber.slice is not a function
16+
17+
Indeed slice is pointed out as not a function on cardNumber.
18+
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
const 12HourClockTime = "8:53pm";
22
const 24hourClockTime = "20:53";
3+
4+
5+
/*
6+
const 12HourClockTime = "8:53pm";
7+
^^
8+
SyntaxError: Invalid or unexpected token
9+
10+
There is something wrong with the syntax, something unexpected, like a typo, or something is in the wrong order.It points to 12. This is because a variable should not start with a number
11+
*/

0 commit comments

Comments
 (0)