Skip to content

Commit 0f95d9b

Browse files
author
russom
committed
Refactor code into reusable function
1 parent c3b0ad5 commit 0f95d9b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@
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 toPound(priceInPence) {
9+
const penceDigits = priceInPence
10+
.substring(0, priceInPence.length - 1)
11+
.padStart(3, "0");
12+
13+
const poundsPart = penceDigits.substring(0, penceDigits.length - 2);
14+
15+
const pencePart = penceDigits.substring(penceDigits.length - 2);
16+
17+
return ${poundsPart}.${pencePart}`;
18+
}
19+
console.log(toPound("399p"));

0 commit comments

Comments
 (0)