Skip to content

Commit 6b7a4ed

Browse files
committed
evalutated each line of code in 3-to-pounds.js file
1 parent 4ad9366 commit 6b7a4ed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const penceStringWithoutTrailingP = penceString.substring(
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
910
const pounds = paddedPenceNumberString.substring(
1011
0,
1112
paddedPenceNumberString.length - 2
@@ -25,6 +26,9 @@ console.log(`£${pounds}.${pence}`);
2526

2627
// To begin, we can start with
2728
/* 1. const penceString = "399p": initializes a string variable with the value "399p"
28-
2. const penceStringWithoutTrailingP = This stores the substring of penceString without a trailing p, so "399p" becomes "399"
29-
3. const paddedPenceNumberString=
29+
2. const penceStringWithoutTrailingP = This stores the substring of penceString by extracting all characters except the final p. It takes the substring from index 0 up to (but not including) the last character p, so "399p" becomes "399". This removes the unit symbol so only the numeric portion remains.
30+
3. const paddedPenceNumberString= This stores the value of penceStringWithoutTrailingP, padded to a total length of 3 characters by adding leading zeros where necessary. This guarantees there are always enough digits to separate pounds and pence correctly.
31+
4. const pounds= Stores the substring of paddedPenceNumberString from index 0 to the last 2 index. These leading digits represent the pound portion of the amount.
32+
5. const pence= Extracts the final two digits of the padded string to represent the pence portion. padEnd(2, "0") ensures that the pence value always contains exactly two digits.
33+
6. console.log(`£${pounds}.${pence}`); logs the value of pounds and pence into a formatted currency string using template literals
3034
*/

0 commit comments

Comments
 (0)