File tree Expand file tree Collapse file tree 1 file changed +2
-8
lines changed
Sprint-1/2-mandatory-errors Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Original file line number Diff line number Diff line change 1313const cardNumber = 4533787178994213;
1414const last4Digits = cardNumber.slice(-4);
1515
16-
1716The issue is that .slice() is a string method, but cardNumber here is a number — not a string.
1817So when the code runs, JavaScript will say something like:
19-
2018TypeError: 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:
2622To use .slice(), we need to convert the number into a string first:
27-
28- Now it works!
2923*/
3024
3125const cardNumber = 4533787178994213 ;
You can’t perform that action at this time.
0 commit comments