Skip to content

Commit 61fd838

Browse files
committed
update: Add prediction and explanation for TypeError in card number slicing in sprint -1 of 3.js
1 parent 6697426 commit 61fd838

File tree

1 file changed

+6
-1
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
// Prediction: The code will not work because the `slice` method is being called on a number type (`cardNumber`),
3+
// and the `slice` method is a string method. In JavaScript, numbers do not have a `slice` method.
4+
// Running the code will likely result in a TypeError.
5+
6+
const last4Digits = cardNumber.toString().slice(-4); // Convert cardNumber to a string first
7+
console.log(`The last 4 digits of the card number are ${last4Digits}`);
38

49
// The last4Digits variable should store the last 4 digits of cardNumber
510
// However, the code isn't working

0 commit comments

Comments
 (0)