Skip to content

Commit 097fe3e

Browse files
Fix cardNumber type for correct slicing of last 4 digits
1 parent 50075e2 commit 097fe3e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
//Explanation: Yes, my prediction was accurate. JavaScript threw a TypeError because '.slice()' is a string method
1616
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
17-
const cardNumber = '4533787178994213';
18-
const last4Digits = cardNumber.slice(-4);
17+
// Keep the original number value untouched
18+
const cardNumber = 4533787178994213;
19+
// Convert to string dynamically before slicing
20+
const last4Digits = cardNumber.toString().slice(-4);
1921

20-
// console.log(last4Digits);
22+
console.log(last4Digits); // output 4213

0 commit comments

Comments
 (0)