File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Sprint-1/2-mandatory-errors Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,15 @@ const last4Digits = cardNumber.slice(-4);
77// Then run the code and see what error it gives.
88// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
99// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10+
11+
12+ //cardNumber is a number and slice does not work with numbers only strings
13+ // to fix this we can convert the number to a string and then use slice
14+ // to get the last 4 characters of the string, which will be the last 4 digits of the original number
15+ // const last4DigitsString = cardNumber.toString().slice(-4);
16+ // or make it into a function that takes a number as an argument and returns the last 4 digits as a string
17+
18+ function last4Digits ( cardNumber )
19+ return `${ cardNumber } ` . slice ( - 4 ) ;
20+
21+ console . log ( last4Digits ( cardNumber ) ) ;
You can’t perform that action at this time.
0 commit comments