Skip to content

Commit 0ca0cc5

Browse files
authored
Update 3-to-pounds.js
1 parent a685e57 commit 0ca0cc5

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ 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+
// 2. Lines 3 to 6: extracts "399" as a string and assigns the values to penceStringWithoutTrailingP.
29+
// It uses the substring to extract from position 0 to 3.
30+
// 3. Line 8: padStart is used to pad the values in penceStringWithoutTrailingP with "0" from the start of the value to make up a length of 3.
31+
// Since penceStringWithoutTrailingP already has "399" with a length of 3, no padding is done.
32+
// 4. Line 9 to 12: substring is used to extract from paddedPenceNumberString, starting from position 0 to 1 giving 3 which is stored in the variable pounds.
33+
// 5. Line 14 to 16: substring is used to extract from paddedPenceNumberString, starting from position 1 to the end givin "99"
34+
// "99" is padded with "0" from the end of the value to make a length of 2 but sincw "99" already has a length of 2, no padding is done.
35+
// "99" is assigned to the variable pence.
36+
// 6. Line 18: uses console.log() to print the values of pounds and pence preceeded by "£" and separated by "." to give "£3.99"
37+

0 commit comments

Comments
 (0)