Skip to content

Commit 50f1a25

Browse files
committed
converted string back to a number
1 parent 8ab1e36 commit 50f1a25

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • Sprint-1/2-mandatory-errors

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

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

44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
@@ -12,4 +12,5 @@ const last4Digits = cardNumber.toString().slice(-4);
1212
// I predict an error will happen because cardNumber is a number and not a string and slice can not be used for pure numbers.
1313
// We can fix it by turning the number into a string by using .toString() before we slice it.
1414

15-
console.log("The last four digits are: " + last4Digits);
15+
console.log("The last four digits are: " + last4Digits);
16+
console.log("This is a " + typeof last4Digits)

0 commit comments

Comments
 (0)