Skip to content

Commit 3da742f

Browse files
committed
Enhance comments
1 parent 25d601f commit 3da742f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ console.log(`£${pounds}.${pence}`);
2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
2828
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the "p" from the string to get "399"
29-
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensure it has at least 3 characters, resulting in "399"
30-
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds part by taking the substring from the start to the length minus 2, resulting in "3"
31-
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part by taking the last two characters and pads it with trailing zeros if necessary, resulting in "99"
32-
// 6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence, which is "£3.99"
29+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensure it has at least 3 characters, resulting in "399" ,
30+
// for example if the input was "99p", it would become "099" after padding, ensuring we can correctly extract pounds and pence in the next steps.
31+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
32+
// extracts the pounds part by taking the substring from the start to the length minus 2, resulting in "3"
33+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"):
34+
// extracts the pence part by taking the last two characters and pads it with trailing zeros if necessary, resulting in "99"
35+
// 6. console.log(`£${pounds}.${pence}`):
36+
// outputs the final formatted price in pounds and pence, which is "£3.99"

0 commit comments

Comments
 (0)