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
// 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"
// 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"
43
43
// 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.
45
45
46
46
// 6. console.log(`£${pounds}.${pence}`);
47
47
// Prints the final formatted price in pounds and pence. An example would be "399p" would print as "£3.99
0 commit comments