File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 11const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
2+ const numberString = cardNumber . toString ( ) ;
3+ const last4Digits = numberString . slice ( - 4 ) ;
4+ const num = Number ( last4Digits ) ;
5+
6+ console . log ( num ) ;
37
48// The last4Digits variable should store the last 4 digits of cardNumber
59// However, the code isn't working
610// Before running the code, make and explain a prediction about why the code won't work
711// Then run the code and see what error it gives.
812// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
913// Then try updating the expression last4Digits is assigned to, in order to get the correct value
14+
15+
16+
17+ // explanation: to see the numbers correctly we need to convert the cardNumber to a string
18+ // first before slicing the last 4 digits. The original code was trying to use slice
19+ // a number, which is not valid. By converting it to a string first,
20+ // we can then slice the last 4 characters correctly. Then we convert it back to a number.
You can’t perform that action at this time.
0 commit comments