Skip to content

Commit 24c4800

Browse files
committed
Step-by-step breakdown of each line in this program
1 parent 9a18e74 commit 24c4800

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,20 @@ 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); :
30+
// Removes the "p" character so only the numeric part of the price remains.
31+
32+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"):
33+
// Ensures the number is at least 3 digits long by adding leading zeros when necessary, which helps with consistent formatting.
34+
35+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); :
36+
// Extracts everything except the last two digits to form the pounds portion of the price.
37+
38+
// 5. const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); :
39+
// Takes the final two digits of the padded string to form the pence portion.
40+
41+
// 6. console.log(`£${pounds}.${pence}`); :
42+
// Combines the pounds and pence into a standard currency format and prints it to the console, "£3.99"
43+
// The program takes a string representing a price in pence (e.g., "399p")
44+
// and converts it to a string representing the price in pounds (e.g., "£3.99").

0 commit comments

Comments
 (0)