There was an error while loading. Please reload this page.
1 parent 0b6a121 commit a680b43Copy full SHA for a680b43
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 toPounds(str) {
9
+ let penceStringWithoutTrailingP = str.substring(0, str.length - 1);
10
11
+ let paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
12
+ let pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
13
14
+ let pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
15
16
+ console.log(`£${pounds}.${pence}`);
17
+}
18
19
+toPounds("5045p")
0 commit comments