Skip to content

Commit ed25b1d

Browse files
committed
fixed typeError by changing cardNumberfrom a number to a string
1 parent 7ec6995 commit ed25b1d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • Sprint-2/2-mandatory-errors

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

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

4-
54
// The last4Digits variable should store the last 4 digits of cardNumber
65
// However, the code isn't working
76
// Before running the code, make and explain a prediction about why the code won't work
87
// Then run the code and see what error it gives.
98
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
109
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
1110

12-
// I predict that it'll throw a syntax error as its not wrapped in "" so it's registering as a number and but it needs to be a string so the .slice() method can register each individual number in last4Digits?
11+
// I predict that it'll throw a syntax error as its not wrapped in "" so it's registering as a number and but it needs to be a string so the .slice() method can register each individual number in last4Digits?
1312
//console.log(last4Digits)
1413
//output: TypeError: cardNumber.slice is not a function
15-
//it's slightly different to what i expected as i thought it was solely about not using the right syntax but it's a type error which after research type error is about not being able to perform a certain operation on a value so here the slice method wouldn't work as .slice() method can only work on strings and arrays so i need to turn cardNumber into a string before the slice() method can work on it. so whilst i was right that it needed "" my reason for why was wrong.
14+
//it's slightly different to what i expected as i thought it was solely about not using the right syntax but it's a type error which after research type error is about not being able to perform a certain operation on a value so here the slice method wouldn't work as .slice() method can only work on strings and arrays so i need to turn cardNumber into a string before the slice() method can work on it. so whilst i was right that it needed "" my reason for why was wrong.
15+
console.log(last4Digits);

0 commit comments

Comments
 (0)