File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed
Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 11const cardNumber = "4533787178994213" ;
2- const last4Digits = cardNumber . slice ( - 4 ) ;
3- console . log ( last4Digits )
2+ const last4Digits = cardNumber . slice ( - 4 ) ;
3+ console . log ( last4Digits ) ;
44
55// The last4Digits variable should store the last 4 digits of cardNumber
66// However, the code isn't working
Original file line number Diff line number Diff line change @@ -22,17 +22,26 @@ console.log(`£${pounds}.${pence}`);
2222
2323// To begin, we can start with
2424// 1. const penceString = "399p": initialises a string variable with the value "399p"
25+
2526// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); Here we use subString() to extracts everything except the last character.
27+
2628// 3.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
29+
2730// padStart(3, "0") ensures the string has at least 3 characters.
2831// If the string is shorter than 3, zeros ("0") are added at the beginning.
2932// If the string is already 3 or more characters, nothing changes.
3033// padStart() ensures the code works for all pence values, including 1-digit and 2-digit numbers.
3134// Without padStart(), the logic would only work correctly for numbers that already have 3 or more digits.
35+
3236// 4.const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
37+
3338// This line used extract the pound value 3 from the padded pence string 399 .
39+
3440// 5.const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
41+
3542//This line extracts the last two digits from paddedPenceNumberString by starting at length - 2 and going to the end.
3643// Then padEnd(2, "0") ensures the pence value always has two digits.
44+
3745// 6.console.log(`£${pounds}.${pence}`);
46+
3847// Here we use console.log() to print our output and merge the pound value and pence value and add pound symbol using template literals.
Original file line number Diff line number Diff line change @@ -18,5 +18,5 @@ Now try invoking the function `prompt` with a string input of `"What is your nam
1818What effect does calling the ` prompt ` function have?
1919It Will open the prompt and asking for the input.
2020What is the return value of ` prompt ` ?
21- prompt() returns a string, or empty string, or null (if Cancel is pressed).
21+ prompt() returns a string, or empty string, or null (if Cancel is pressed).
2222
You can’t perform that action at this time.
0 commit comments