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": initialises a string variable with the value "399p".
28
+
// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1): represent to takes a substring from index 0 up to (but not including) penceString.length - 1.
29
+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): assign to ensures the numeric string is at least 3 characters long by adding leading zeros if needed.
30
+
// 4. const pounds = paddedPenceNumberString.substring( 0,paddedPenceNumberString.length - 2): Takes the substring from the start up to (but not including) the last two characters.
31
+
// 5. substring(length - 2) : use to returns the last two characters (the pence digits). padEnd(2, "0") would append trailing zeros if the result were shorter than 2.
32
+
// 6. console.log(`£${pounds}.${pence}`): assign to display the price in a human-readable pounds-and-pence format (£x.yy)
0 commit comments