File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -25,3 +25,22 @@ console.log(`£${pounds}.${pence}`);
25
25
26
26
// To begin, we can start with
27
27
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28
+
29
+ // 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
30
+ // Removes the trailing "p" from the string, leaving just the numeric part (e.g., "399").
31
+
32
+ // 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
33
+ // Pads the numeric string on the left with zeros so it is at least 3 characters long (e.g., "9" becomes "009").
34
+ // This ensures consistent formatting for the next steps.
35
+
36
+ // 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
37
+ // Extracts all but the last two characters to represent the pounds part (e.g., from "399", it takes "3").
38
+
39
+ // 5. const pence = paddedPenceNumberString
40
+ // .substring(paddedPenceNumberString.length - 2)
41
+ // .padEnd(2, "0");
42
+ // Extracts the last two characters for the pence part (e.g., from "399", it takes "99").
43
+ // If there are fewer than two characters, it pads the result on the right with zeros.
44
+
45
+ // 6. console.log(`£${pounds}.${pence}`);
46
+ // Outputs the formatted price in pounds and pence
You can’t perform that action at this time.
0 commit comments