There was an error while loading. Please reload this page.
1 parent 50075e2 commit 097fe3eCopy full SHA for 097fe3e
1 file changed
Sprint-2/2-mandatory-errors/3.js
@@ -14,7 +14,9 @@
14
15
//Explanation: Yes, my prediction was accurate. JavaScript threw a TypeError because '.slice()' is a string method
16
// 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);
+// Keep the original number value untouched
+const cardNumber = 4533787178994213;
19
+// Convert to string dynamically before slicing
20
+const last4Digits = cardNumber.toString().slice(-4);
21
-// console.log(last4Digits);
22
+console.log(last4Digits); // output 4213
0 commit comments