Skip to content

Commit 6fca6cb

Browse files
committed
add to pounds
1 parent 79e1444 commit 6fca6cb

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ const pence = paddedPenceNumberString
1717

1818
console.log(${pounds}.${pence}`);
1919

20-
// This program takes a string representing a price in pence
20+
// This program takes a string representindng a price in pence
2121
// The program then builds up a string representing the price in pounds
2222

2323
// You need to do a step-by-step breakdown of each line in this program
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
// const penceString = "399p": initialises a string variable with the value "399p"
29+
// 1. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): creates a new string variable that removes the last character "p" from the original string
30+
// 2. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): creates a new string variable that pads the original string with leading zeros to make it 3 characters long
31+
// 3. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds portion of the string by taking all characters except the last two
32+
// 4. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence portion of the string by taking the last two characters and pads it with trailing zeros to make it 2 characters long
33+
// 5. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console

0 commit comments

Comments
 (0)