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 = cardNumber . toString ( ) . slice ( - 4 ) ;
33
44// The last4Digits variable should store the last 4 digits of cardNumber
55// However, the code isn't working
66// Before running the code, make and explain a prediction about why the code won't work
7+
8+ The code didnt work because the slice method was called on an integer ( cardNumber ) ,
9+ but slice is a method that is only available for strings and arrays .
10+ Since cardNumber is an integer , it does not have the slice method ,
11+ which will result in an error when the code is run .
12+
713// Then run the code and see what error it gives.
14+ The error was : TypeError : cardNumber . slice is not a function
15+
816// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
17+ It gives this error because the slice method is not meant for numbers . This is what I predicted , as I expected that calling slice on an integer would result in a TypeError .
18+
919// Then try updating the expression last4Digits is assigned to, in order to get the correct value
20+
21+ const last4Digits = cardNumber . toString ( ) . slice ( - 4 ) ;
You can’t perform that action at this time.
0 commit comments