Skip to content

Commit 9c35713

Browse files
committed
Solution: mandatory-interpret, 3-to-pounds
1 parent c09b8c7 commit 9c35713

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,23 @@ console.log(`£${pounds}.${pence}`);
2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

26-
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
26+
// Step 1: initialize the string variable penceString with the value "399p"
27+
// const penceString = "399p";
28+
29+
// Step 2: Remove the "p" from the end of "399p" and store the value to penceStringWithoutTrailingP
30+
// const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1);
31+
32+
// Step 3: The padStart method is used to ensure that the paddedPenceNumberString string variable has at least 3
33+
// characters, padding it with "0" at the start if necessary. Since paddedPenceNumberString is already 3 characters
34+
// long, no padding is added.
35+
// const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
36+
37+
// Step 4: The substring method is used to extract the pounds part of the price and store it in the variable pounds.
38+
// const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
39+
40+
// Step 5: The substring method is used to extract the pence part of the price and store it in the variable pence.
41+
// It uses the padEnd method to ensure that the pence string has at least 2 characters, padding it with "0" at the end if necessary.
42+
// const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
43+
44+
// Step 6: The console.log method is used to output the final price in pounds and pence format.
45+
// console.log(`£${pounds}.${pence}`);

0 commit comments

Comments
 (0)