Skip to content

Commit 9e74f96

Browse files
Enhance comments for clarity in pence to uk format pounds conversion
1 parent 0ed56e5 commit 9e74f96

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
@@ -1,21 +1,25 @@
11
const penceString = "399p";
2-
2+
// it creates a string representing a price in pence,the p at the end indicates the unit.
33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7-
7+
// it removes the trailing "p" from the penceString, leaving only the numeric part of the string.
88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
//Insure the numeric string has at least 3 characters, padding it with 0 if needed.
910
const pounds = paddedPenceNumberString.substring(
1011
0,
1112
paddedPenceNumberString.length - 2
1213
);
13-
14+
// Takes all digits except the last two to represent the pounds part of the price.
1415
const pence = paddedPenceNumberString
1516
.substring(paddedPenceNumberString.length - 2)
1617
.padEnd(2, "0");
17-
18+
// Takes the last two digits to represent the pence part of the price, ensuring it has two characters.
1819
console.log(${pounds}.${pence}`);
20+
// it logs the final price in pounds and pence format : "£3.99"
21+
22+
1923

2024
// This program takes a string representing a price in pence
2125
// The program then builds up a string representing the price in pounds

0 commit comments

Comments
 (0)