Skip to content

Commit 97aaeda

Browse files
committed
mandatory errors 3
1 parent 74a3d77 commit 97aaeda

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = cardNumber.toString().slice(-4);
3+
console.log(last4Digits);
34

45
// The last4Digits variable should store the last 4 digits of cardNumber
56
// However, the code isn't working
67
// Before running the code, make and explain a prediction about why the code won't work
78
// Then run the code and see what error it gives.
89
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
910
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
11+
// returns an error because the slice method is not available for numbers. The slice method is a string method, and cardNumber is a number.
12+
// To fix this, we need to convert cardNumber to a string before using the slice method. We can do this by using the toString() method or by using template literals.

0 commit comments

Comments
 (0)