File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 1- const cardNumber = 4533787178994213 ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
31
42// The last4Digits variable should store the last 4 digits of cardNumber
53// However, the code isn't working
64// Before running the code, make and explain a prediction about why the code won't work
75// Then run the code and see what error it gives.
86// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
97// Then try updating the expression last4Digits is assigned to, in order to get the correct value
8+
9+
10+ // const cardNumber = 4533787178994213;
11+ // const last4Digits = cardNumber.(-4);
12+
13+ // console.log(last4Digits);
14+
15+
16+
17+ // String.prototype.slice()
18+ // The slice() method of String values extracts a section of this string and returns it as a new string,
19+ // without modifying the original string. but in this example we have number we can extract this.
20+ // 1 slice work only with String
21+ // 2 we have to convert the variable to String
22+ // 3 Option we can just added a single quotation but this variable is saving number.
23+
24+
25+ const cardNumber = 4533787178994213 ;
26+ const last4Digits = cardNumber . toString ( ) . slice ( - 4 ) ;
27+
28+ console . log ( last4Digits ) ;
You can’t perform that action at this time.
0 commit comments