Skip to content

Commit 0996658

Browse files
author
JorvanW
committed
made 3-to-pounds into a function
1 parent f5c1935 commit 0996658

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55

66
// You should call this function a number of times to check it works for different inputs
77

8-
const penceString = "399p";
9-
10-
const penceStringWithoutTrailingP = penceString.substring(
11-
0,
12-
penceString.length - 1
13-
);
14-
15-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
16-
const pounds = paddedPenceNumberString.substring(
17-
0,
18-
paddedPenceNumberString.length - 2
19-
);
20-
21-
const pence = paddedPenceNumberString
22-
.substring(paddedPenceNumberString.length - 2)
23-
.padEnd(2, "0");
24-
25-
console.log(${pounds}.${pence}`);
26-
8+
function toPounds(penceString) {
9+
const penceStringWithoutTrailingP = penceString.substring(
10+
0,
11+
penceString.length - 1
12+
);
13+
14+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15+
const pounds = paddedPenceNumberString.substring(
16+
0,
17+
paddedPenceNumberString.length - 2
18+
);
19+
20+
const pence = paddedPenceNumberString
21+
.substring(paddedPenceNumberString.length - 2)
22+
.padEnd(2, "0");
23+
24+
return ${pounds}.${pence}`;
25+
}
26+
27+
console.log(toPounds("399p"));

0 commit comments

Comments
 (0)