Skip to content

Commit cfe1b0c

Browse files
changed to function and commented with alternative changes
1 parent 578f816 commit cfe1b0c

File tree

1 file changed

+12
-0
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+12
-0
lines changed

Sprint-1/2-mandatory-errors/3.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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));

0 commit comments

Comments
 (0)