Skip to content

Commit 78253f1

Browse files
committed
fixed the error in 3.js and the code now runs
1 parent 4ffd303 commit 78253f1

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

  • Sprint-1/2-mandatory-errors

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
1+
//const cardNumber = 4533787178994213;
2+
//const last4Digits = cardNumber.slice(-4);
3+
4+
5+
// to fix the code, we'll convert the number to a string because .slice does not work on number data type
6+
let cardNumber = 4533787178994213;
7+
cardNumber = cardNumber.toString()
8+
let last4Digits = cardNumber.slice(-4);
39

410
// The last4Digits variable should store the last 4 digits of cardNumber
511
// However, the code isn't working
612
// Before running the code, make and explain a prediction about why the code won't work
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?
915
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
16+
17+
//Answer
18+
// We are not logging to the console
19+
// The slice method should be a positive number to represent the index position.
20+
21+
console.log(last4Digits)
22+
//TypeError: cardNumber.slice is not a function

0 commit comments

Comments
 (0)