Skip to content

Commit 6f38725

Browse files
completed_3-to-pounds.js
1 parent 22e28cd commit 6f38725

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const penceString = "399p";
22

3-
const penceStringWithoutTrailingP = penceString.substring(
3+
const penceStringWithoutTrailingP = penceString.substring( // 399
44
0,
55
penceString.length - 1
66
);
77

8-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
const pounds = paddedPenceNumberString.substring(
8+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //399
9+
const pounds = paddedPenceNumberString.substring( //3
1010
0,
1111
paddedPenceNumberString.length - 2
1212
);
@@ -23,5 +23,10 @@ console.log(`£${pounds}.${pence}`);
2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

26-
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
26+
27+
//3. This line truncates the string by index, excluding the last character, without the letter p.
28+
//8. This line is needed in case the variable length is shorter than 3 characters. If the variable value is less than 1 pound, calling the padStart() function guarantees that there are 3 characters so that we can later convert pence to the 0.00 format (we will add the decimal point later).
29+
//9. saves the entire string except for the last 2 characters, i.e. the number of pounds
30+
//14. saves the value of the last two characters, i.e. the number of pence
31+
//18. this line outputs the final value in the standard format £0.00
32+

0 commit comments

Comments
 (0)