Skip to content

Commit c1aeb97

Browse files
committed
exercies 3-to-pounds solved
1 parent 96f2e35 commit c1aeb97

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
@@ -1,10 +1,9 @@
1-
const penceString = "399p";
1+
const penceString = "105p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
66
);
7-
87
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
98
const pounds = paddedPenceNumberString.substring(
109
0,
@@ -25,3 +24,22 @@ console.log(`£${pounds}.${pence}`);
2524

2625
// To begin, we can start with
2726
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27+
// 2.
28+
// 3. const penceStringWithoutTrailingP = penceString.substring( : declares new var and assigns the pence string excluding trailing p
29+
// 4. 0, : first value of the function, this is to tell the function to start from the first charachtar in the string
30+
// 5. penceString.length - 1 : second value of the funtion, it takes the string lengs mines 1 (to exclude trailing p)
31+
// 6. ); : closed th funtion.
32+
// 7. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); : it padds the number with 0 from the start (to make number readable and clear)
33+
// 8. const pounds = paddedPenceNumberString.substring( : declares new variable to store pounds, it takes the last two numbers from the number and stores everything that is before the last two numbers because they are pence not pounds.
34+
// 9. 0, : set 0 to start from the first character.
35+
// 10. paddedPenceNumberString.length - 2 : here is where it excludes the last two numbers (the pence).
36+
// 11. ); : closes function.
37+
// 12.
38+
// 13. const pence = paddedPenceNumberString : declares new var to store pence
39+
// 14. .substring(paddedPenceNumberString.length - 2) : identifies the last two numbers (pence) and stores them.
40+
// 15. .padEnd(2, "0"); : to pad the pence with 0 from the end
41+
// 16.
42+
// 17. console.log(`£${pounds}.${pence}`); : to write the result, it prints the two variables, pounds and pence. it adds £ to show that it's pound.
43+
44+
45+

0 commit comments

Comments
 (0)