Skip to content

Commit a680b43

Browse files
committed
Conversion function from sprint 2, to-pounds
1 parent 0b6a121 commit a680b43

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,16 @@
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(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

Comments
 (0)