Skip to content

Commit 599ea52

Browse files
correcting typos and making the explanation clearer
1 parent 3ea132c commit 599ea52

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ console.log(`£${pounds}.${pence}`);
2828

2929
// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1);
3030
// penceString.length -1: points to the index just before the last character. The substring(0, ect) takes everything from the start up to the last character (but not including the last character)
31-
// The result removes th trailing "p" so the output becomes "399p" --> "399"
31+
// The result removes the trailing "p" so the output becomes "399p" --> "399"
3232

3333
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");:
3434
// Ensures the pence int has at least 3 characters by adding leading zeros if required.
3535
// This is useful for values under 100p so the pounds/pence split works accurately.
3636

3737
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
3838
// This takes everything except the last two digits
39-
// The last two digits represent the pence, so whatever is left over fro the calculation is the pounds.
39+
// The last two digits represent the pence, so whatever is left over from the calculation is the pounds.
4040

4141
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
42-
// The substring(paddedPenceNumberString.length - 2) takes the last two characters as the pence part "399" and converts it into "99"
42+
// The substring(paddedPenceNumberString.length - 2) takes the last two characters of the padded string (e.g. "399") and extacts the pence portion "99"
4343
// The .padEnd(2, "0") ensures the pence part is always 2 digits by adding trailing zeros if needed.
44-
// In most cases there are already two digits, however part of the code protects against edge cases such as "3" becoming "30" which would be an inaccurate outcome.
44+
// In most cases there are already two digits, however part of the code protects against outputs such as "3" becoming "30" which would be an inaccurate outcome.
4545

4646
// 6. console.log(`£${pounds}.${pence}`);
4747
// Prints the final formatted price in pounds and pence. An example would be "399p" would print as "£3.99

0 commit comments

Comments
 (0)