Skip to content

Commit d402f08

Browse files
committed
changed carNumber tostring so that it works with slice.
1 parent 731baca commit d402f08

File tree

1 file changed

+7
-1
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = cardNumber.toString().slice(-4);
3+
4+
// Prediction: the second vairable assignemment will give an error because the slice method canno be used on a number. we will get a type error
5+
6+
//when i ran the code a got an error saying cardNumber.slice is not a function. this is because the slice method only works on strings and arrays whilst cardNumber is a number.
7+
8+
console.log(last4Digits);
39

410
// The last4Digits variable should store the last 4 digits of cardNumber
511
// However, the code isn't working

0 commit comments

Comments
 (0)