File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Sprint-1/2-mandatory-errors Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1+ // const cardNumber = 4533787178994213;
2+ // const last4Digits = cardNumber.slice(-4);
3+ // prediction: The code will not work because the `slice` method is being called on a number and has not yet been converted into a string.
4+
5+ // this code will throw an error.
6+ // console.log(last4Digits);
7+ // The error i was given: cardNumber.slice is not a function
8+ // Explanation: The error occurs because cardNumber is a number, and the slice method is for a string method.
9+
10+ // To fix this, we need to convert `cardNumber` to a string before using the `slice` method by adding .toString() to the cardNumber variable.
111const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
12+ const last4Digits = cardNumber . toString ( ) . slice ( - 4 ) ;
13+ console . log ( last4Digits ) ; // This should now correctly log "4213"
314
415// The last4Digits variable should store the last 4 digits of cardNumber
516// However, the code isn't working
You can’t perform that action at this time.
0 commit comments