There was an error while loading. Please reload this page.
1 parent dfbeb67 commit 92253f5Copy full SHA for 92253f5
1 file changed
Sprint-3/3-mandatory-implement/3-to-pounds.js
@@ -4,3 +4,19 @@
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
+ let withOutP = penceString.substring( 0,penceString.length - 1);
10
+ let paddedPenceNumberString = withOutP.padStart(3, "0");
11
+ const pounds = paddedPenceNumberString.substring(0 ,paddedPenceNumberString.length - 2);
12
+ const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
13
+ return `£${pounds}.${pence}`
14
+}
15
16
17
+console.log(toPounds("502p"));
18
19
20
+//output for 4050p is £40.50
21
+//output for 29p is £0.29
22
+//output for 502 is £5.02
0 commit comments