We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 258e0b2 commit a065b32Copy full SHA for a065b32
1 file changed
Sprint-2/3-mandatory-implement/3-to-pounds.js
@@ -4,3 +4,18 @@
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 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