@@ -25,3 +25,48 @@ 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+ console . log ( penceStringWithoutTrailingP )
30+
31+ // 3. const penceStringWithoutTrailingP = penceString.substring(
32+ // initialises a string variable with value "399" by using function substring on penceString
33+
34+ // 4. 0,
35+ // first argument for substring, taking part of the string starting from the first letter
36+
37+ // 5. penceString.length - 1
38+ // second argument for substring, taking the string up until the 3rd letter
39+ // done by taking the whole string length (.length) of 4 and removing 1 (this removes the 'p')
40+
41+ // 6. );
42+ // closes the arguments for the function
43+
44+ console . log ( paddedPenceNumberString )
45+
46+ // 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
47+ // Ensures the string is at least 3 in length, and if not adds zeros to the front
48+ // This is to ensure later calculations don't return negative values
49+
50+ // 9-12. const pounds = paddedPenceNumberString.substring(
51+ // 0,
52+ // paddedPenceNumberString.length - 2
53+ // );
54+ // Performing same function as lines 3 to 6, taking the padded string and removing the last two digits
55+ // these are the digits representing pence, leaving a string that represents pounds and intialising
56+ // that as a pounds variable of 3
57+
58+ // 14. const pence = paddedPenceNumberString
59+ // intialising new pence variable
60+
61+ // 15. .substring(paddedPenceNumberString.length - 2)
62+ // performing substring function on the padded string this time for pence by starting the substring
63+ // from the penultimate (-2) character of the padded string length
64+
65+
66+ // 16. .padEnd(2, "0");
67+ // ensures the pence string is at least 2 characters long, adding a zero to the start if not
68+ // closing this function returns 99 to the variable pence
69+
70+ // 18. console.log(`£${pounds}.${pence}`);
71+ // takes the pounds and pence variables and prints them to the log as a string with a decimal divider and added pound sign
72+ // at the start: £3.99
0 commit comments