You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* 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
0 commit comments