There was an error while loading. Please reload this page.
1 parent d8b60b7 commit 20b12f0Copy full SHA for 20b12f0
1 file changed
Sprint-3/3-mandatory-implement/3-to-pounds.js
@@ -4,3 +4,31 @@
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
9
10
11
12
+function toPounds(amount) {
13
+ const amountWithoutTrailingP = amount.substring(
14
+ 0,
15
+ amount.length - 1
16
+);
17
18
+const paddedPenceNumberString = amountWithoutTrailingP.padStart(3, "0");
19
+const pounds = paddedPenceNumberString.substring(
20
21
+ paddedPenceNumberString.length - 2
22
23
24
+const pence = paddedPenceNumberString
25
+ .substring(paddedPenceNumberString.length - 2)
26
+ .padEnd(2, "0");
27
28
+ return (`£${pounds}.${pence}`)
29
+}
30
31
32
+console.log(toPounds("1250p"));
33
34
0 commit comments