Skip to content

Commit 7b042b7

Browse files
Refine comments for clarity and consistency in the price conversion logic
1 parent fd72b0f commit 7b042b7

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ console.log(`£${pounds}.${pence}`);
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27-
// 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"
27+
// 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: Uses padStart() to ensure the string is at least 3 digits long by adding leading "0"s if needed (e.g., "5" becomes "005"), ensuring there are enough digits to extract both pounds and pence.
30+
// 4. const pounds: Uses substring() to remove/discard the final two digits (which represent the pence) and keep everything before them, extracting the whole pounds value ("3").
31+
// 5. const pence: Uses substring() to extract only the final two digits ("99") for the pence value, using padEnd() as a safeguard to keep it at two digits.
32+
// 6. console.log(`£${pounds}.${pence}`): Uses template literals to format and display the final price string ("£3.99").

0 commit comments

Comments
 (0)