Skip to content

Commit 70b961f

Browse files
committed
JavaScript error corrections
1 parent c78c840 commit 70b961f

5 files changed

Lines changed: 32 additions & 7 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
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+
//The error message displayed by Node.js is:
5+
//Uncaught SyntaxError: Unexpected identifier 'is'
6+
//This is a syntax error. It occurs because JavaScript is trying to interpret an
7+
//English sentence as JavaScript code. After reading the word 'This', the JavaScript
8+
//parser expects a valid JavaScript operator. Instead, it encounters another variable
9+
//name, 'is', which is not valid in that position according to JavaScript's syntax rules.
10+
//As a result, the parser throws the error Unexpected identifier 'is'.

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
const age = 33;
44
age = age + 1;
5+
6+
//The error message displayed by Node.js is:
7+
//Uncaught TypeError: Assignment to constant variable
8+
//The error happens because const creates a variable whose value cannot be reassigned.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2-
// what's the error ?
2+
// what's the error?
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
//The error message displayed by Node.js is:
8+
//Uncaught ReferenceError: cityOfBirth is not defined
9+
//The error occurs because the variable 'cityofBirth' is used before it has been declared.

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.slice(-4);
33

4-
// The last4Digits variable should store the last 4 digits of cardNumber
5-
// However, the code isn't working
6-
// Before running the code, make and explain a prediction about why the code won't work
4+
// The last4Digits variable should store the last 4 digits of cardNumber.
5+
// However, the code isn't working.
6+
// 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?
9-
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
9+
// Then try updating the expression last4Digits is assigned to, in order to get the correct value.
10+
11+
//The error message displayed by Node.js is:
12+
//Uncaught TypeError: cardNumber.slice is not a function
13+
//The error occurs because slice() is a string method, but the variable 'cardNumber' is a number.
14+
//To get the last four digits, the number must be converted to a string.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
const 12HourClockTime = "8:53pm";
22
const 24hourClockTime = "20:53";
3+
4+
//The error message displayed by Node.js is:
5+
//Uncaught SyntaxError: Invalid or unexpected token
6+
//This error happens because JavaScript does not allow variable names to start with a number.

0 commit comments

Comments
 (0)