Skip to content

Commit a065b32

Browse files
pence fix
1 parent 258e0b2 commit a065b32

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,18 @@
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+
function toPounds(penceString) {
9+
const withoutP = penceString.slice(0, -1);
10+
11+
const padded = withoutP.padStart(3, "0");
12+
13+
const pounds = padded.slice(0, -2);
14+
const pence = padded.slice(-2);
15+
16+
return ${pounds}.${pence}`;
17+
}
18+
19+
console.log(toPounds("399p"));
20+
console.log(toPounds("45p"));
21+
console.log(toPounds("5p"));

0 commit comments

Comments
 (0)