Skip to content

Commit 4252fe6

Browse files
committed
Explained why code failed and updated last4Digits to convert cardNumber into a string
1 parent da67e68 commit 4252fe6

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 won't work because cardNumber is defined as a number not a string.
2+
// The slice method is a string and arrays method, and can't 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)