Skip to content

Commit 6468f29

Browse files
committed
Add detailed explanation for pounds extraction in 3-to-pounds.js
1 parent 893336e commit 6468f29

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ console.log(`£${pounds}.${pence}`);
3333

3434
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
3535
// penceStringWithoutTrailingP is now '399'
36-
// padStart(3, "0") is a method which guarantees that the numeric string is at least 3 characters long, and if it is shorter add '0' to the front until it is 3 characters long.
36+
// padStart(3, "0") is a method used above which guarantees that the numeric string is at least 3 characters long, and if it is shorter add '0' to the front until it is 3 characters long.
3737
// padding to 3 ensures there is always at least one pounds digit and two pence digits.
38+
39+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
40+
// since paddedPenceNumberString is '399' and it's '.length' is 3
41+
// this line is saying: '399.substring(0, 3 - 2)', which becomes '399.substring(0, 1)'
42+
// 'substring' is a method used to grab characters from a string, starting from the left, from position '0' up to, but not including, position '1'
43+
// 'const pounds' would be assigned the new value: '3'

0 commit comments

Comments
 (0)