Skip to content

Commit 8ccf3b2

Browse files
committed
Mandatory-errors part is finished.
1 parent c882576 commit 8ccf3b2

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3-
4-
console.log(`I was born in ${cityOfBirth}`);
53
const cityOfBirth = "Bolton";
4+
console.log(`I was born in ${cityOfBirth}`);
5+
6+
//Code was correct, I just shifted the const part to the top of the code block.

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = cardNumber.toString().slice(-4);
3+
4+
5+
console.log(last4Digits);
36

47
// The last4Digits variable should store the last 4 digits of cardNumber
58
// However, the code isn't working
69
// Before running the code, make and explain a prediction about why the code won't work
710
// Then run the code and see what error it gives.
811
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
912
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
13+
14+
15+
// Prediction; code wont work because slice is for strings, not numbers.
16+
17+
// after running the code, I got an error saying "cardNumber.slice is not a function".
18+
19+
// It's what I predicted.
20+
21+
// to fix the code I need to convert number to string first, then slice it.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
1+
//const 12HourClockTime = "20:53";
2+
//const 24hourClockTime = "08:53";
3+
4+
5+
// problem is in javascript we cant start a variable name with a number.
6+
7+
// correct way is:
8+
9+
const.twelveHourClockTime = "20:53";
10+
const twentyFourHourClockTime = "08:53";
11+
12+
console.log(`The time in 12-hour format is ${twelveHourClockTime} and in 24-hour format is ${twentyFourHourClockTime}`);

0 commit comments

Comments
 (0)