File tree Expand file tree Collapse file tree
Sprint-2/2-mandatory-errors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const cardNumber = 4533787178994213 ;
1+ const cardNumber = " 4533787178994213" ;
22const last4Digits = cardNumber . slice ( - 4 ) ;
3+ console . log ( last4Digits ) ;
34
45// The last4Digits variable should store the last 4 digits of cardNumber
56// However, the code isn't working
67// Before running the code, make and explain a prediction about why the code won't work
8+
9+ The code is not working because the "slice" method is being used incorrectly . The "slice"
10+ method should be called on the string "cardNumber" to extract the last 4 digits . However ,
11+ if there is a syntax error or if the variable "cardNumber" is not defined correctly , it could lead to an error .
12+
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?
15+ It gives an error because the "slice" method is being called on a string , but if the string is not defined correctly or
16+ if there is a typo in the variable name , it will result in an error . This is what I predicted , as
17+ I anticipated that the issue would be related to how the "slice" method is being used on the string .
18+
919// Then try updating the expression last4Digits is assigned to, in order to get the correct value
20+
21+ I updated the expression to correctly use the "slice " method on the "cardNumber " string . I converted the cardNumber to a
22+ string with the ( "" ) and then used the slice method to extract the last 4 digits .
You can’t perform that action at this time.
0 commit comments