Skip to content

Commit 0e9535d

Browse files
committed
did a step by step breakdown of turning a string into pounds
1 parent db7d71e commit 0e9535d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Sprint-1/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. penceString.substring(0, penceString.length - 1): removes the trailing "p" by taking all characters except the last one -> "399"
29+
// 3. paddedPenceNumberString = "399".padStart(3, "0"): ensures the string is at least 3 characters long, padding with "0" on the left if needed. "399" stays "399" but "5p" would become "005"
30+
// 4. pounds = paddedPenceNumberString.substring(0, length - 2): takes everything except the last 2 digits, giving the pounds part -> "3"
31+
// 5. pence = paddedPenceNumberString.substring(length - 2).padEnd(2, "0"): takes the last 2 digits for the pence -> "99". padEnd ensures it stays 2 digits e.g. "5" would become "50"
32+
// 6. console.log prints the final result combining pounds and pence -> £3.99

0 commit comments

Comments
 (0)