Skip to content

Commit dc0e00d

Browse files
committed
Converting a number to use slice function and display the last 4 digits
1 parent cedc8a3 commit dc0e00d

File tree

1 file changed

+2
-8
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+2
-8
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,13 @@
1313
const cardNumber = 4533787178994213;
1414
const last4Digits = cardNumber.slice(-4);
1515
16-
1716
The issue is that .slice() is a string method, but cardNumber here is a number — not a string.
1817
So when the code runs, JavaScript will say something like:
19-
2018
TypeError: cardNumber.slice is not a function
19+
That’s because .slice() function only works on strings or arrays — and numbers don’t have that method.
2120
22-
That’s because .slice() only works on strings or arrays — and numbers don’t have that method.
23-
24-
Fixing the problem
25-
21+
Fixing the problem:
2622
To use .slice(), we need to convert the number into a string first:
27-
28-
Now it works!
2923
*/
3024

3125
const cardNumber = 4533787178994213;

0 commit comments

Comments
 (0)