Skip to content

Commit 9977d32

Browse files
committed
Completed all tasks in mandatory errors folder
1 parent b181b7c commit 9977d32

5 files changed

Lines changed: 38 additions & 7 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
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?
3+
4+
// the answer: by using "//" on each line

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
// const age = 33;
4+
// age = age + 1;
5+
6+
// the error is in line 4. It's a "TypeError: Assignment to constant variable", which was thrown because the value to
7+
// a specific constant can only be assigned once (which is done in line 3 already).
8+
// This wouldn't throw an error if instead of const, the let was used
9+
10+
let age = 33;
411
age = age + 1;
12+
console.log(age);

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

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

4-
console.log(`I was born in ${cityOfBirth}`);
4+
// console.log(`I was born in ${cityOfBirth}`);
5+
// 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
9+
510
const cityOfBirth = "Bolton";
11+
console.log(`I was born in ${cityOfBirth}`);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
2+
//const last4Digits = cardNumber.slice(-4);
23
const last4Digits = cardNumber.slice(-4);
4+
console.log(last4Digits);
35

46
// The last4Digits variable should store the last 4 digits of cardNumber
57
// However, the code isn't working
68
// Before running the code, make and explain a prediction about why the code won't work
79
// Then run the code and see what error it gives.
810
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
911
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
12+
13+
// I thought it was something to do with the slice "-4" (but i turned out i forgot that negative indices start at -1, not 0)
14+
// The actual error indicates that on the 3rd line there is a typeError: "cardNumber.slice is not a function"
15+
// Checked the error reference and decided to look more closely. Noticed that the card number is used as a number,
16+
// so it answers why the function couldn't be called - because they can be only called on Arrays and Strings.
17+
// Therefore, I'll add parentheses to turn the card number into a string (so that the function could be called)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
const 12HourClockTime = "8:53pm";
2-
const 24hourClockTime = "20:53";
1+
// const 12HourClockTime = "8:53pm";
2+
// const 24hourClockTime = "20:53";
3+
4+
// SyntaxError: Invalid or unexpected token.
5+
// it turns out that in JS variable names cannot begin with a number
6+
7+
const HourClockTime12 = "8:53pm";
8+
const HourClockTime24 = "20:53";
9+
console.log(HourClockTime24);

0 commit comments

Comments
 (0)