Skip to content

Commit 3231aad

Browse files
committed
describ line by line code
1 parent 3c79ff2 commit 3231aad

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
5-
penceString.length - 1
5+
penceString.length - 1,
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
11-
paddedPenceNumberString.length - 2
11+
paddedPenceNumberString.length - 2,
1212
);
1313

1414
const pence = paddedPenceNumberString
@@ -25,3 +25,15 @@ 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. penceStringWithoutTrailingP : it's value is the return of the method substring()which is 399.
30+
// the substring(0,3-1),when the substring extracts string from index 0 to 2 =>399 and p will be dropped.
31+
32+
// 3. paddedPenceNumberString : its value is what the padstart() method returns which is the same.399
33+
//padstart(3,0),it is supossed to add 0's till the needed length is reached which is 3=>399.
34+
35+
// 4. const Pound is initialized by the out come of the substring()method which is only 3. Because the
36+
// substring start index is zero and end endex is 1.
37+
// 5. const pence will be initialized there are two methods. the first one will extract the string form index 1
38+
// the second one will add 0 which there is no need=> 99
39+
//6.consol.log => 3.99

0 commit comments

Comments
 (0)