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
+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): creates a new string variable that contains the
29
+
// original string without the last character (the "p").
30
+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): creates a new string variable
31
+
// that pads the previous string with leading zeros until it is at least 3 characters long. eg. "45" becomes "045" and "7" becomes "007".
32
+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): creates a new string variable that contains
33
+
// the first part of the padded string, which represents the pounds. It takes all characters except the last two. eg. "045" becomes "0" and "399" becomes "3".
34
+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): creates a new string variable that contains the
35
+
// last two characters of the padded string, which represents the pence. It also pads it with trailing zeros if necessary to ensure it is 2 characters long.
36
+
// eg. "045" becomes "45" and "7" becomes "70".
37
+
// 6. console.log(`£${pounds}.${pence}`): outputs the final price in pounds and pence format to the console. For example, if penceString is "399p",
38
+
// it will output "£3.99". If penceString is "45p", it will output "£0.45". If penceString is "7p", it will output "£0.07".
0 commit comments