Skip to content

Commit 62b453f

Browse files
commented what each line of code does
1 parent 54c1b63 commit 62b453f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const penceString = "399p";
1+
const penceString = "399p";
22

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

8-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
8+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //399
99
const pounds = paddedPenceNumberString.substring(
1010
0,
1111
paddedPenceNumberString.length - 2
12-
);
12+
); //3
1313

1414
const pence = paddedPenceNumberString
1515
.substring(paddedPenceNumberString.length - 2)
@@ -25,3 +25,22 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
29+
//2. const penceStringWithoutTrailingP = penceString.substring(
30+
// 0,
31+
// penceString.length - 1
32+
// ); : it creates a variable with the value "399" by eliminating the character at index penceString.length - 1
33+
34+
//3.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");:initialises a string variable of at least 3 characters,
35+
// if it has les than 3 characters it adds 0 to make up for it
36+
37+
//4.const pounds = paddedPenceNumberString.substring(
38+
//0,
39+
// paddedPenceNumberString.length - 2
40+
// );:initialises a string variable with the value of paddedPenceNumberString except the last 2 characters
41+
42+
//5.const pence = paddedPenceNumberString
43+
// .substring(paddedPenceNumberString.length - 2)
44+
// .padEnd(2, "0");: takes the last 2 characters from paddedPenceNumberString , it has to be 2 characters long if not it will add a 0 for
45+
// every missing character
46+
//it adds a dot between pounds and pence and logs 3.99

0 commit comments

Comments
 (0)