Skip to content

Commit 498c331

Browse files
committed
wrote full description of what I think each line does in the code
1 parent 78ff809 commit 498c331

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ 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. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): takes of the p at the end of the string.
29+
// 3.const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): creates a paddded pencestring value so that if the value has less than 3 digits it gets padded with 0s at the start to make it 3 digits.
30+
// 4. const pounds = paddedPenceNumberString.substring(0,paddedPenceNumberString.length - 2): creates a variable that holds the pound value of the string by removing the last 2 digits of the padded pence string.
31+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): creates a variable that holds the pence value of the string by taking the last 2 digits of the padded pence string and if there is only one digit it pads it with a 0 at the end to make it 2 digits.
32+
// 6. console.log(`£${pounds}.${pence}`): prints out the final value in pounds and pence format.

0 commit comments

Comments
 (0)