Skip to content

Commit 8f50754

Browse files
committed
Explained why slice() failed on a number and updated last4Digits to convert cardNumber to a string
1 parent bad8580 commit 8f50754

File tree

1 file changed

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

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
// Prediction: The code will not work because cardNumber is defined as a number not a string.
2+
// The slice method is a string and arrays method, and cannot be used on a number type.
3+
// Error: TypeError: cardNumber.slice is not a function
4+
15
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
6+
const last4Digits = cardNumber.toString().slice(-4);
7+
8+
console.log(last4Digits); // Should output: 4213
39

410
// The last4Digits variable should store the last 4 digits of cardNumber
511
// However, the code isn't working

0 commit comments

Comments
 (0)