Skip to content

Commit 92253f5

Browse files
committed
wrote the code and tested the code with different value
1 parent dfbeb67 commit 92253f5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

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

Comments
 (0)