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
+
27
28
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29
+
30
+
//2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length-1) initialises a string variable that has a value of penceString without the last character
31
+
32
+
//3. const paddedPenceString = pence~StringWithourTrailingP.padStart(3,'0') initialises a string variable that has the value of penceStringWithoutTrailingP but ensures the string is at least 3 characters long by adding 0's to the start if needed
33
+
34
+
//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2) initialises a string variable that has the value of paddedPenceNumberString without the last 2 characters
35
+
36
+
//5. const pence = paddedPenceNumberString.subString(paddedPenceNumberString.length-2).padEnd(2,'0') initialises a string variale with the value of the last 2 characters of paddedPenceNumberString and ensures the string is at least 2 characters long by adding 0's to the end if needed
37
+
38
+
//6. console.log(`£${pounds}.${pence}`) prints out the value of pounds and pence in £pounds.pence format by using string interpolation
0 commit comments