Skip to content

Commit dbf28af

Browse files
committed
Complete pounds conversion interpretation
1 parent 28d1d37 commit dbf28af

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ 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 final "p" character so only the digits remain
29+
// 3. padStart(3, "0"): ensures the value has at least 3 characters by adding leading zeros if needed
30+
// 4. pounds = the first part of the padded string, excluding the last two digits, so the whole pounds part is preserved
31+
// 5. pence = the final two digits, padded to 2 characters, to keep a valid pence value
32+
// 6. console.log(`£${pounds}.${pence}`): prints the formatted result as a pounds and pence string
33+
34+
// For "399p", the steps work like this:
35+
// "399p" -> "399" -> "399" -> pounds = "3" and pence = "99" -> output "£3.99"

0 commit comments

Comments
 (0)