Skip to content

Commit 629157a

Browse files
committed
convert to pounds
1 parent 1b215b8 commit 629157a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,29 @@
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+
function convertToPound(srt) {
8+
const penceStringWithoutTrailingP = srt.substring(0, srt.length - 1);
9+
10+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
11+
12+
const pounds = paddedPenceNumberString.substring(
13+
0,
14+
paddedPenceNumberString.length - 2
15+
);
16+
17+
return pounds;
18+
}
19+
20+
function convertToPence(srt) {
21+
const penceStringWithoutTrailingP = srt.substring(0, srt.length - 1);
22+
23+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
24+
25+
const pence = paddedPenceNumberString
26+
.substring(paddedPenceNumberString.length - 2)
27+
.padEnd(2, "0");
28+
29+
return pence;
30+
}
31+
32+
console.log(${convertToPound("399p")}.${convertToPence("399p")}`);

0 commit comments

Comments
 (0)