Skip to content

Commit 4db1ee4

Browse files
answered question in comments on price conversion logic and the purpose behind the steps
1 parent a6d27f3 commit 4db1ee4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +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"
27+
// 1. const penceString = "399p": initializes a string variable with the value "399p"
28+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing 'p' from the string, resulting in "399"
29+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399"
30+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds part from the padded string, which is "3"
31+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part from the padded string, ensuring it has 2 digits, resulting in "99"
32+
// 6. console.log(`£${pounds}.${pence}`): logs the final formatted price in pounds, which is "£3.99"

0 commit comments

Comments
 (0)