Skip to content

Commit e8de7c3

Browse files
- Add detailed explanation for substring, padStart, and padEnd methods
- Explain the string methods for converting pence to pounds currency format - Verify output of formatted currency string ('£3.99') via Node.js
1 parent 5f58ebd commit e8de7c3

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
// 2. const penceStringWithoutTrailingP: uses substring to remove the trailing "p" from "399p", leaving "399"
29+
// 3. const paddedPenceNumberString: padStart() makes sure the string has at least 3 characters, adding "0" if required. If we have "5p" and we remove the "p" we would be left with "5", so padding it to 3 numbers will give us the output ("005")
30+
// const pounds: removes everything except the final two digits, giving "3".
31+
// 4. const pence = paddedPenceNumberString: extracts the final two digits, giving "99", and ensures they have at least two characters and adds zero if necessary.
32+
// 5. console.log(`£${pounds}.${pence}`): combines the pound and pence values into the formatted price with the template literals to give "£3.99"

0 commit comments

Comments
 (0)