Skip to content

Commit 2c371d5

Browse files
committed
Fix cardNumber definition to use string format and ensure last4Digits extraction works correctly
1 parent 9de5303 commit 2c371d5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
const cardNumber = 4533787178994213;
1+
const cardNumber = "4533787178994213";
22
const last4Digits = cardNumber.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
8+
9+
The code is not working because the "slice" method is being used incorrectly. The "slice"
10+
method should be called on the string "cardNumber" to extract the last 4 digits. However,
11+
if there is a syntax error or if the variable "cardNumber" is not defined correctly, it could lead to an error.
12+
713
// Then run the code and see what error it gives.
814
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
15+
It gives an error because the "slice" method is being called on a string, but if the string is not defined correctly or
16+
if there is a typo in the variable name, it will result in an error. This is what I predicted, as
17+
I anticipated that the issue would be related to how the "slice" method is being used on the string.
18+
919
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
20+
21+
I updated the expression to correctly use the "slice" method on the "cardNumber" string. I converted the cardNumber to a
22+
string with the ("") and then used the slice method to extract the last 4 digits.

0 commit comments

Comments
 (0)