Skip to content

Commit 72be197

Browse files
committed
answered 3-to-pounds.js
1 parent 30949fb commit 72be197

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const penceString = "399p";
1+
const penceString = "104569p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
@@ -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. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): Removes the "p" from the end.
29+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): Makes the string at least 3 letters long by adding "0"s to the front.
30+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): Grabs everything except the last two digits to find the "pound" amount.
31+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): Grabs exactly the last two digits.
32+
// 6. console.log(`£${pounds}.${pence}`): Combines the pounds and pence with a decimal point and a "£" symbol.

0 commit comments

Comments
 (0)