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 11const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
2+ const last4Digits = String ( cardNumber ) . slice ( - 4 ) ;
3+
4+ console . log ( last4Digits )
35
46// The last4Digits variable should store the last 4 digits of cardNumber
57// However, the code isn't working
68// Before running the code, make and explain a prediction about why the code won't work
9+
10+ // .slice needs to act on a string not a number, so I would expect something like 'incorrect input' as an error
11+
712// Then run the code and see what error it gives.
813// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
14+
15+ // TypeError: cardNumber.slice is not a function
16+ // This is not exactly the words I expected the error to say but is correctly identifying the same error
17+ // I think it is saying that cardNumber.slice is not a function of a number, hence the TypeError
18+
919// Then try updating the expression last4Digits is assigned to, in order to get the correct value
20+
21+ // I converted cardNumber to a string and error resolved and it return the correct output
You can’t perform that action at this time.
0 commit comments