Skip to content

Commit ee4627a

Browse files
committed
explained the purpose of each function and the use of each step
1 parent 784ff5d commit ee4627a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const penceString = "399p";
1+
const penceString = "1399p"; // stores the price in pence as a string with a trailing 'p'
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
6-
);
6+
); // removes the trailing 'p' from the string to isolate the numeric part
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
1111
paddedPenceNumberString.length - 2
12-
);
12+
); // extracts the pounds part by taking all but the last two characters
1313

1414
const pence = paddedPenceNumberString
15-
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
15+
.substring(paddedPenceNumberString.length - 2) // extracts the last two characters as the pence part
16+
.padEnd(2, "0"); // ensures the pence part is two digits by padding with '0' if necessary
1717

18-
console.log(${pounds}.${pence}`);
18+
console.log(${pounds}.${pence}`); // outputs the formatted price in pounds and pence
1919

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

0 commit comments

Comments
 (0)