File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -25,3 +25,56 @@ 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+ // creates a string that represents a price in pence, including the letter "p"
30+ //
31+ // Example: "399p"
32+ //
33+ // This is the original input value we want to convert into pounds.
34+
35+
36+ // 2. const penceStringWithoutTrailingP = ...
37+ // Uses substring to remove the last character ("p") from the string
38+ //
39+ // We take the string from index 0 up to (but not including) the last character
40+ //
41+ // Result: "399"
42+ //
43+ // This leaves us with only the numeric part of the price as a string.
44+
45+
46+ // 3. const paddedPenceNumberString = ...
47+ // padStart ensures the string is at least 3 characters long
48+ //
49+ // This is important for small values like "5p":
50+ // "5" becomes "005"
51+ //
52+ // Result for "399": "399"
53+ // Result for "5p": "005"
54+
55+
56+ // 4. const pounds = ...
57+ // Extracts all characters except the last two
58+ //
59+ // The last two characters represent pence,
60+ // everything before that represents pounds
61+ //
62+ // For "399":
63+ // pounds = "3"
64+
65+
66+ // 5. const pence = ...
67+ // Takes the last two characters of the string
68+ //
69+ // padEnd ensures the pence value is always two digits
70+ //
71+ // For "399":
72+ // pence = "99"
73+
74+
75+ // 6. console.log(`£${pounds}.${pence}`)
76+ // Combines pounds and pence into a formatted price string
77+ //
78+ // Final output:
79+ // £3.99
80+
You can’t perform that action at this time.
0 commit comments