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
// Try and describe the purpose / rationale behind each step
25
25
26
26
// To begin, we can start with
27
-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27
+
// 1. const penceString = "399p": initializes a string variable with the value "399p"
28
+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing 'p' from the string
29
+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures the string has at least 3 characters by padding with leading zeros if necessary
30
+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds part of the string (all but the last two characters)
31
+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part (the last two characters) and pads with trailing zeros if necessary
32
+
// 6. console.log(`£${pounds}.${pence}`): formats and prints the final price in pounds and pence format
0 commit comments