Skip to content

Commit b83f152

Browse files
committed
Added breakdown of code converting pence string to pound format.
1 parent 34c796a commit b83f152

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ 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+
29+
30+
// 2: "const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1)"__ Removes the trailing "p" character.
31+
// substring(0,penceString.length - 1) this code gets all characters except the last one. so "399p" becomes just"399".
32+
// 3: const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0") Ensures the pence string that has at least 3 digits, by padding it in left with "0" if needed for example: 399 stays 399 or 7 would become 007.
33+
// 4: const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2) Extracts the pound portion (except the last two one) __ "399"-"3"(pounds)
34+
// 5: const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") Gets the last two digits as the pence part. for example: "399"__"99"(pence)
35+
// padEnd(2, "0") ensures at least two digits for pence.__eg: "3"_"30".
36+
// 6: console.log(`£${pounds}.${pence}`) logs the full formatted price in pounds and pence.__eg:for "399P" pounds"3" pence"99" and the result is __ "3.99"

0 commit comments

Comments
 (0)