File tree Expand file tree Collapse file tree
Sprint-3/3-mandatory-implement Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
9+
10+ function toPence ( penceString ) {
11+
12+ const penceStringWithoutTrailingP = penceString . substring (
13+ 0 ,
14+ penceString . length - 1
15+ ) ;
16+
17+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
18+ const pounds = paddedPenceNumberString . substring (
19+ 0 ,
20+ paddedPenceNumberString . length - 2
21+ ) ;
22+
23+ const pence = paddedPenceNumberString
24+ . substring ( paddedPenceNumberString . length - 2 )
25+ . padEnd ( 2 , "0" ) ;
26+
27+ return ( `£${ pounds } .${ pence } ` )
28+ } ;
29+
30+ console . log ( toPence ( '399p' ) ) ; // output £3.99
31+ console . log ( toPence ( '50p' ) ) ; // output £0.50
32+ console . log ( toPence ( '1200p' ) ) ; // output £12.00
33+ console . log ( toPence ( '5p' ) ) ; // output £0.05
You can’t perform that action at this time.
0 commit comments