Skip to content

Commit 32d7119

Browse files
committed
Enhance comments to provide a detailed step-by-step explanation of the pence to pounds conversion process
1 parent 496d1b8 commit 32d7119

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ 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+
// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1): This removes the letter 'p' from the end of the string,
30+
// leaving just the numbers part of the string. The substring method is used to extract a portion of the string,
31+
// starting from index 0 and ending at the second-to-last character (length - 1).
32+
33+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); This is to ensure the numbers presented after the substring is at least 3 characters long,
34+
// if the number is shorter the computer would add '0' or '0's in front of the number to make it 3 digits long.
35+
36+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2):
37+
// This extracts the pounds part of the string by taking all characters except the last two.
38+
39+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
40+
// This extracts the pence part of the string by taking the last two characters and ensures that it is at least 2 characters long by adding '0' at the end
41+
// if necessary as this is because we need the decimal value.
42+
43+
// 6. console.log(`£${pounds}.${pence}`): This outputs the final answer in the format of pounds and allows the user to see the final result also.

0 commit comments

Comments
 (0)