Skip to content

Commit 4c83857

Browse files
committed
Add error message and explanation for cardNumber slicing issue
1 parent 466f652 commit 4c83857

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ const last4Digits = cardNumber.slice(-4);
1313
//Prediction - The code would not run because 'cardNumber' is declared as numbers instead of a string.
1414
// The '.slice()' method belongs to strings and arrays, it could only work by treating it's subject as a sequence of characters.
1515

16-
console.log(last4Digits);
16+
console.log(last4Digits);
17+
18+
//Error message - TypeError: cardNumber.slice is not a function
19+
//Reason for error
20+
//The error thrown was considerably as predicted.
21+
//'.slice()' is a method defined on 'String.prototype', and since 'cardNumber' was declared with a numeric literal, JavaScript treats it as the 'number' type.

0 commit comments

Comments
 (0)