Skip to content

Commit 770d48e

Browse files
committed
Complete to pounds interpret exercise
1 parent 23c71b9 commit 770d48e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
5-
penceString.length - 1
5+
penceString.length - 1,
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
11-
paddedPenceNumberString.length - 2
11+
paddedPenceNumberString.length - 2,
1212
);
1313

1414
const pence = paddedPenceNumberString
@@ -25,3 +25,8 @@ 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+
// 2. Removes the trailing "p" from penceString, changing "399p" to "399".
29+
// 3. Pads the pence string with leading zeros so it has at least 3 characters.
30+
// 4. Extracts all digits except the last two to get the pounds part of the price.
31+
// 5. Extracts the last two digits to get the pence part and ensures it has two digits.
32+
// 6. Formats the pounds and pence as a price and prints it to the console.

0 commit comments

Comments
 (0)