Skip to content

Commit 20b12f0

Browse files
Complete £ function
1 parent d8b60b7 commit 20b12f0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎Sprint-3/3-mandatory-implement/3-to-pounds.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,31 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// You should call this function a number of times to check it works for different inputs
7+
8+
9+
10+
11+
12+
function toPounds(amount) {
13+
const amountWithoutTrailingP = amount.substring(
14+
0,
15+
amount.length - 1
16+
);
17+
18+
const paddedPenceNumberString = amountWithoutTrailingP.padStart(3, "0");
19+
const pounds = paddedPenceNumberString.substring(
20+
0,
21+
paddedPenceNumberString.length - 2
22+
);
23+
24+
const pence = paddedPenceNumberString
25+
.substring(paddedPenceNumberString.length - 2)
26+
.padEnd(2, "0");
27+
28+
return (`£${pounds}.${pence}`)
29+
}
30+
31+
32+
console.log(toPounds("1250p"));
33+
34+

0 commit comments

Comments
 (0)