Skip to content

Commit 20eeeea

Browse files
committed
answered all questions in 3-to-pounds.js
1 parent bae8454 commit 20eeeea

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const penceStringWithoutTrailingP = penceString.substring(
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9+
910
const pounds = paddedPenceNumberString.substring(
1011
0,
1112
paddedPenceNumberString.length - 2
@@ -25,3 +26,16 @@ console.log(`£${pounds}.${pence}`);
2526

2627
// To begin, we can start with
2728
// 1. const penceString = "399p": initialises a string variable with the value "399p"
29+
// 3. we are declaring a variable and assigning it the variable penceString which holds the value "399p" but without the p - the method .subString is used
30+
// here to remove the p.
31+
// 8. we are declaring a variable and assigning it the variable penceStringWithoutTrailingP which holds the value "399
32+
// we are then using the .padStart method, however the method will not make any change because we have passed in the argument 3 which i
33+
// is the total length the string should be after padding - our string is already 3 lengths long.
34+
// 10. we are using a substring to slice our string from the first index to paddedPenceNumberString.length - 2, paddedPenceNumberString.length
35+
// will give us the number 3, so paddedPenceNumberString.length - 2 also means 3 - 2 which gives us 1, so from index 0 which is 3 to index 1 which is exclusive.
36+
// 15. we are declaring a variable pence and assigning it the variable paddedPenceNumberString which holds the result of a couple
37+
// method chains, firstly a .substring method with the argument "paddedPenceNumberString.length - 2" which also means 3 - 2, so it will
38+
// slice from index 1 to the end as we have not given a second argument, then we follow with a padEnd, this time we are adding
39+
// characters to the end of the string - we want a total of two characters
40+
//19. we use a string template to console log
41+

0 commit comments

Comments
 (0)