File tree Expand file tree Collapse file tree
Sprint-1/2-mandatory-errors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
1+ //const cardNumber = 4533787178994213;
2+ //const last4Digits = cardNumber.slice(-4);
3+
4+
5+ // to fix the code, we'll convert the number to a string because .slice does not work on number data type
6+ let cardNumber = 4533787178994213 ;
7+ cardNumber = cardNumber . toString ( )
8+ let last4Digits = cardNumber . slice ( - 4 ) ;
39
410// The last4Digits variable should store the last 4 digits of cardNumber
511// However, the code isn't working
612// Before running the code, make and explain a prediction about why the code won't work
713// Then run the code and see what error it gives.
814// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
915// Then try updating the expression last4Digits is assigned to, in order to get the correct value
16+
17+ //Answer
18+ // We are not logging to the console
19+ // The slice method should be a positive number to represent the index position.
20+
21+ console . log ( last4Digits )
22+ //TypeError: cardNumber.slice is not a function
You can’t perform that action at this time.
0 commit comments