@@ -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
@@ -25,3 +25,29 @@ console.log(`£${pounds}.${pence}`);
2525
2626// To begin, we can start with
2727// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
29+ // 2. const penceStringWithoutTrailingP = penceString.substring(
30+ // 0,
31+ // penceString.length - 1
32+ //);
33+ // finds a substring starting at 0 index to 1 before the last index, and assigns the
34+ // substring to penceStringWithoutTrailingP. This removes the p and leaves us with just
35+ // the number
36+
37+ // 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
38+ // Makes it so that the string is always at least 3 characters, by adding leading 0 until
39+ // it is 3 characters long.
40+
41+ // 4. const pounds = paddedPenceNumberString.substring(
42+ // 0,
43+ // paddedPenceNumberString.length - 2,
44+ //);
45+ // Finds the substring of number paddedPenceNumberString, with the last 2 digits cut off
46+ // basically finds the number of pounds by cutting off the pence
47+
48+ // 5. const pence = paddedPenceNumberString
49+ // .substring(paddedPenceNumberString.length - 2)
50+ // .padEnd(2, "0");
51+ // Takes the substring starting at the total length-2, to the end. Essentially taking the
52+ // last 2 digits
53+ // Then adds 0 to the beginning so it is at least 2 characters long
0 commit comments