@@ -2,13 +2,13 @@ const penceString = "399p";
22
33const penceStringWithoutTrailingP = penceString . substring (
44 0 ,
5- penceString . length - 1
5+ penceString . length - 1 ,
66) ;
77
88const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
99const pounds = paddedPenceNumberString . substring (
1010 0 ,
11- paddedPenceNumberString . length - 2
11+ paddedPenceNumberString . length - 2 ,
1212) ;
1313
1414const pence = paddedPenceNumberString
@@ -24,4 +24,12 @@ console.log(`£${pounds}.${pence}`);
2424// Try and describe the purpose / rationale behind each step
2525
2626// 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+ // 3-6. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
29+ // : initializes a variable, the value of which is turned to numerical by removing the letter "p".
30+ // 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
31+ // Here the padstart function turns "399" string into 399 number (it could add some zeroes in front, but here it serves as a converter)
32+ // 9-12. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
33+ // Here the goal is to initialize a variable of Pounds (with the value of 3), by splitting it from 99, and it's done using the substring method
34+ // 14-16. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
35+ // Here the pence variable is introduced with the value of 99 and it's done by taking the 399 and removing 3 using substring and padEnd methods.
0 commit comments