Skip to content

Commit ba1300d

Browse files
committed
refactoring the code by use toStr() for dynamic values instead of % formatting
1 parent 7309397 commit ba1300d

File tree

1 file changed

+4
-3
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
77
// .slice() called on a number, and Numbers don’t have string methods like .slice().it will throw an error
88
// console.log(last4Digits) => TypeError: cardNumber.slice is not a function at Object.
9-
const cardNumber = 4533787178994213;
9+
const cardNumber = 4533787178994213;;
1010
// const last4Digits = cardNumber.toString;
11-
const last4Digits = cardNumber % 10000;
12-
console.log(last4Digits)
11+
const numToStr = cardNumber.toString()
12+
const last4Digits = numToStr.slice(-4)
13+
console.log(last4Digits) //===>4213

0 commit comments

Comments
 (0)