There was an error while loading. Please reload this page.
1 parent 0fee258 commit 6e72bf1Copy full SHA for 6e72bf1
1 file changed
Sprint-3/3-mandatory-implement/3-to-pounds.js
@@ -4,3 +4,22 @@
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
+ if (penceString == "") {
10
+ return "please put the amount";
11
+ }
12
+ const totalPence = parseInt(penceString, 10);
13
+ const pounds = totalPence / 100;
14
+ const formattedPound = pounds.toFixed(2);
15
+ return "£" + formattedPound;
16
+}
17
18
+console.log(toPounds("1991p"));
19
+console.log(toPounds("2020p"));
20
+console.log(toPounds("399p"));
21
+console.log(toPounds("69p"));
22
+console.log(toPounds("00p "));
23
+console.log(toPounds(" 50p "));
24
+console.log(toPounds("232423"));
25
+console.log(toPounds(""));
0 commit comments