Skip to content

Commit ae59e28

Browse files
committed
edited answer to 2-mandatory errors
1 parent ae3b1cd commit ae59e28

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

  • Sprint-1/2-mandatory-errors

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const cardNumber = "4533787178994213";
2-
const last4Digits = cardNumber.slice(-4);
1+
const cardNumber = 4533787178994213;
2+
const last4Digits = cardNumber.toString().slice(-4);
33

4-
console.log(last4Digits);
54
// I thought the issue might be something to do with the number given (-4) but it's actually the fact that cardNumber.slice is not a function.
65
// Slice is not a function for numbers - it's for strings
7-
// To solve this we can turn the card number into a string
6+
// To solve this we can turn the card number into a string by using toString() - this converts the number to a string temporarily rather than changing the card number to a string itself.

0 commit comments

Comments
 (0)