Skip to content

Commit 1d0edb2

Browse files
committed
answered the questions to 3-to-pounds.js
1 parent 655acb6 commit 1d0edb2

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ 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+
3-6. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1)
30+
This is taking penceString and removing the p from it so its just a string with the numerical letters only.
31+
32+
8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
33+
This is taking penceStringWithoutTrailingP ensuring that the minimum length of the numerical string is at least 3 numbers.
34+
It is filling out with 0s from the front so if it was 3 it would have 003
35+
36+
9-12. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
37+
this is taking paddedPenceNumberString and removing the last 2 numerical numbers from the string/
38+
This takes the 399 and makes it 3
39+
40+
41+
14-16. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
42+
This is taking paddedPenceNumberString and first reduces the length to the last 2 numbers in the string.
43+
It then uses padEnd to ensure that there is a at least two 00 if no numbers are present.
44+
45+
18. console.log(`£${pounds}.${pence}`);
46+
This shows the pounds and pence with a £ at the start and a . between them.
47+
making this show the pence to pounds as £3.99
48+
*/

0 commit comments

Comments
 (0)