|
1 | | -// The last4Digits variable should store the last 4 digits of cardNumber |
2 | | -// However, the code isn't working |
3 | | -// Before running the code, make and explain a prediction about why the code won't work |
4 | | -// Then run the code and see what error it gives. |
5 | | -// Consider: Why does it give this error? Is this what I predicted? If not, what's different? |
6 | | -// Then try updating the expression last4Digits is assigned to, in order to get the correct value |
7 | | -// The code would result a TypeError. Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number |
8 | | -// The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. |
9 | | -const cardNumber = 4533787178994213; |
10 | | -const last4Digits = String(cardNumber).slice(-4); |
11 | | - |
12 | | -console.log(last4Digits); |
| 1 | +// The last4Digits variable should store the last 4 digits of cardNumber |
| 2 | +// However, the code isn't working |
| 3 | +// Before running the code, make and explain a prediction about why the code won't work |
| 4 | +// Then run the code and see what error it gives. |
| 5 | +// Consider: Why does it give this error? Is this what I predicted? If not, what's different? |
| 6 | +// Then try updating the expression last4Digits is assigned to, in order to get the correct value |
| 7 | +// Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number |
| 8 | +// The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. |
| 9 | +// The code would result a TypeError. |
| 10 | +const cardNumber = 4533787178994213; |
| 11 | +const last4Digits = String(cardNumber).slice(-4); |
| 12 | + |
| 13 | +console.log(last4Digits); |
0 commit comments