Skip to content

Commit b9108fd

Browse files
debug2604debug2604
authored andcommitted
Correct substring argument explanation in 3-to-pounds.js
1 parent f0d0c8b commit b9108fd

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const penceString = "399p"; // initialises a string variable with the value "399p"
1+
const penceString = "399"; // initialises a string variable with the value "399p"
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
@@ -14,7 +14,9 @@ const pounds = paddedPenceNumberString.substring(
1414

1515
const pence = paddedPenceNumberString
1616
.substring(paddedPenceNumberString.length - 2)
17-
.padEnd(2, "0"); // declares variable for pence. Argument -2 of .substring method returns the last two characters.
17+
.padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2,
18+
// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two
19+
// characters "99" — not a literal -2 argument.
1820
// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99".
1921

2022
console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane.

0 commit comments

Comments
 (0)