There was an error while loading. Please reload this page.
1 parent c3b0ad5 commit 0f95d9bCopy full SHA for 0f95d9b
1 file changed
Sprint-3/3-mandatory-implement/3-to-pounds.js
@@ -4,3 +4,16 @@
4
// You will need to declare a function called toPounds with an appropriately named parameter.
5
6
// 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