Skip to content

Commit 6e72bf1

Browse files
committed
implementing the function that changes different input in to pounds
1 parent 0fee258 commit 6e72bf1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎Sprint-3/3-mandatory-implement/3-to-pounds.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,22 @@
44
// You will need to declare a function called toPounds with an appropriately named parameter.
55

66
// 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

Comments
 (0)