Skip to content

Commit cd349dc

Browse files
committed
add answers
1 parent d26014e commit cd349dc

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • Sprint-1/2-mandatory-errors

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
console.log(cardNumber.toString());
3+
const cardNumber1 = cardNumber.toString()
4+
const last4Digits = cardNumber1.slice(-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
10+
// I think slice () works for strings or arrays not for numbers. That's why the code won't work.
711
// Then run the code and see what error it gives.
12+
// After running code TypeError: cardNumber.slice is not a function this error shows.
813
// 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
14+
// It gives this error because cardNumber doesn't have slice method. My prediction was beacuse
15+
// cardNumber is number not string and the difference is that slice method called but it
16+
// doesn't exist on that type.
17+
// Then try updating the expression last4Digits is assigned to, in order to get the correct
18+
// value
19+
// Updated the expression in order to get in to the correct value.

0 commit comments

Comments
 (0)