Skip to content

Commit 170c5b8

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
added solution to 3.js
1 parent 5308baa commit 170c5b8

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • Sprint-1/2-mandatory-errors

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
const cardNumber = 4533787178994213;
2-
const last4Digits = cardNumber.slice(-4);
2+
const last4Digits = String(cardNumber).slice(-4);
3+
4+
console.log(last4Digits)
35

46
// The last4Digits variable should store the last 4 digits of cardNumber
57
// However, the code isn't working
68
// Before running the code, make and explain a prediction about why the code won't work
9+
10+
// .slice needs to act on a string not a number, so I would expect something like 'incorrect input' as an error
11+
712
// Then run the code and see what error it gives.
813
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
14+
15+
// TypeError: cardNumber.slice is not a function
16+
// This is not exactly the words I expected the error to say but is correctly identifying the same error
17+
// I think it is saying that cardNumber.slice is not a function of a number, hence the TypeError
18+
919
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
20+
21+
// I converted cardNumber to a string and error resolved and it return the correct output

0 commit comments

Comments
 (0)