File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff 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").
You can’t perform that action at this time.
0 commit comments