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": initialises a string variable with the value "399p"
28
+
//3-5. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): creates a new string variable that contains the original string without the last character (the "p"), resulting in "399"
29
+
//8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399"
30
+
//9-11. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the substring representing the pounds by taking all characters except the last two, resulting in "3"
31
+
//14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the last two characters to represent the pence and pads it with trailing zeros if necessary, resulting in "99"
32
+
//18. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence, resulting in "£3.99"
0 commit comments