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+ console . log ( cardNumber . toString ( ) ) ;
3+ const cardNumber1 = cardNumber . toString ( )
4+ const last4Digits = cardNumber1 . slice ( - 4 ) ;
5+ console . log ( last4Digits ) ;
36
47// The last4Digits variable should store the last 4 digits of cardNumber
58// However, the code isn't working
69// Before running the code, make and explain a prediction about why the code won't work
10+ // I think slice () works for strings or arrays not for numbers. That's why the code won't work.
711// Then run the code and see what error it gives.
12+ // After running code TypeError: cardNumber.slice is not a function this error shows.
813// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
9- // Then try updating the expression last4Digits is assigned to, in order to get the correct value
14+ // It gives this error because cardNumber doesn't have slice method. My prediction was beacuse
15+ // cardNumber is number not string and the difference is that slice method called but it
16+ // doesn't exist on that type.
17+ // Then try updating the expression last4Digits is assigned to, in order to get the correct
18+ // value
19+ // Updated the expression in order to get in to the correct value.
You can’t perform that action at this time.
0 commit comments