Skip to content

Commit 013ef5e

Browse files
author
JorvanW
committed
Updated code and changed answer in line 14 and 15 to 3.js
1 parent ffbb9a4 commit 013ef5e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • Sprint-1/2-mandatory-errors

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const cardNumber = "4533787178994213";
2-
const last4Digits = cardNumber.slice(-4);
1+
const cardNumber = 4533787178994213;
2+
const last4Digits = String(cardNumber).slice(-4);
33

44
// The last4Digits variable should store the last 4 digits of cardNumber
55
// However, the code isn't working
@@ -11,4 +11,6 @@ const last4Digits = cardNumber.slice(-4);
1111
//Prediction: I believe the code won't work because the slice method is incorrect. The slice method is used for strings.
1212
//Error: TypeError: cardNumber.slice is not a function
1313
//Needed to add "" to make it a string.
14+
//if not possible, I can change make the last4Digits = String(cardNumber).slice(-4);
15+
// to make last4Digits to convert cardNumber into a string
1416

0 commit comments

Comments
 (0)