Skip to content

Commit 624bb88

Browse files
author
Diana Ausiejute
committed
Finished all 4 mandatory errors
1 parent dd868f0 commit 624bb88

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

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

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
const age = 33;
44
age = age + 1;
55

6-
// the error is in line 4. It's a "TypeError: Assignment to constant variable", which happened because the value to
7-
// a constant can only be assigned once (as it's )
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

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
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)
18+

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

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

0 commit comments

Comments
 (0)