Skip to content

Commit 68ca43b

Browse files
Implement pence to pounds conversion
1 parent bf8cbcb commit 68ca43b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,23 @@ 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+
30+
// 1. const penceString = "399p"
31+
// Initialises a string variable with the value "399p"
32+
33+
// 2. penceString.substring(0, penceString.length - 1)
34+
// Removes the final "p", leaving "399"
35+
36+
// 3. penceStringWithoutTrailingP.padStart(3, "0")
37+
// Makes the string 3 characters long by adding "0" at the beginning if needed.
38+
39+
// 4. paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2)
40+
// Takes everything except the final two characters to get the pounds
41+
42+
// 5. paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0")
43+
// Takes the final two characters to get the pence and adds "0" at the end if needed
44+
45+
// 6. console.log(`£${pounds}.${pence}`)
46+
// Displays the price in pounds and pence, such as £3.99
47+

0 commit comments

Comments
 (0)