You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Currently trying to print the string "I was born in Bolton" but it isn't working...
2
-
// what's the error ?
2
+
// what's the error ? in line 4 the variable cityOfBirth is being used before it is declared. We should declare the variable before using it in the console.log statement.
// The last4Digits variable should store the last 4 digits of cardNumber
5
5
// However, the code isn't working
6
6
// Before running the code, make and explain a prediction about why the code won't work
7
7
// Then run the code and see what error it gives.
8
8
// Consider: Why does it give this error? Is this what I predicted? If not, what's different?
9
9
// Then try updating the expression last4Digits is assigned to, in order to get the correct value
10
+
11
+
// the code is not working becuase slide method is for strings where as cardNumber is a number. We should convert the cardNumber to string before using slice method.
12
+
//Synax error in line 2, but the result is not clear from the output.
13
+
14
+
constlast4Digits=cardNumber.toString().slice(-4);
15
+
console.log(`The last 4 digits of ${cardNumber} are ${last4Digits}`);
);// removes the last character "p" from the penceString and stores the result in a new variable called penceStringWithoutTrailingP. The substring method is used to extract a portion of the string, starting from index 0 and ending at the second-to-last index (length - 1).
6
+
);
7
+
// The substring method is used to extract a portion of the string, starting from index 0 and ending at the second-to-last index (length - 1).
//padStart method is used to add leading zeros to the penceStringWithoutTrailingP until it reaches a length of 3 characters. The result is stored in a new variable called paddedPenceNumberString.
10
+
//padStart method is used to add leading zeros to the penceStringWithoutTrailingP until it reaches a length of 3 characters
11
+
// The result is stored in a new variable called paddedPenceNumberString.
12
+
//esure that to represent like 0.09 or 3.99
10
13
constpounds=paddedPenceNumberString.substring(
11
14
0,
12
15
paddedPenceNumberString.length-2
13
16
);
14
-
//
17
+
//slice the paddedPenceNumberString until the last two characters, which represent the pounds.
15
18
constpence=paddedPenceNumberString
16
19
.substring(paddedPenceNumberString.length-2)
17
20
.padEnd(2,"0");
21
+
//slice the last two characters of the paddedPenceNumberString, which represent the pence.
22
+
// by using penEnd method esure the it is two characters long. if it is not add zeros to end.
0 commit comments