Skip to content

Commit 90591fb

Browse files
committed
Implement pence to pounds conversion in 3-to-pounds.js
1 parent 60a26a1 commit 90591fb

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,27 @@
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+
function toPounds(pence) {
11+
const penceValue = pence.slice(0, -1).padStart(3, "0");
12+
return ${penceValue.slice(0, -2)}.${penceValue.slice(-2)}`;
13+
}
14+
15+
console.log(toPounds("90p"));
16+
17+
let penceArray = [
18+
["399p", "£3.99"],
19+
["9p", "£0.09"],
20+
["50p", "£0.50"],
21+
["1002p", "£10.02"],
22+
["1900p", "£19.00"],
23+
];
24+
for (const [input, expectedOutput] of penceArray) {
25+
const currentOutput = toPounds(input);
26+
console.assert(
27+
currentOutput === expectedOutput,
28+
`Current output is ${currentOutput}. Expected outout is ${expectedOutput}`
29+
);
30+
}

0 commit comments

Comments
 (0)