File tree Expand file tree Collapse file tree
Sprint-2/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+ function convertToPound ( srt ) {
8+ const penceStringWithoutTrailingP = srt . substring ( 0 , srt . length - 1 ) ;
9+
10+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
11+
12+ const pounds = paddedPenceNumberString . substring (
13+ 0 ,
14+ paddedPenceNumberString . length - 2
15+ ) ;
16+
17+ return pounds ;
18+ }
19+
20+ function convertToPence ( srt ) {
21+ const penceStringWithoutTrailingP = srt . substring ( 0 , srt . length - 1 ) ;
22+
23+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
24+
25+ const pence = paddedPenceNumberString
26+ . substring ( paddedPenceNumberString . length - 2 )
27+ . padEnd ( 2 , "0" ) ;
28+
29+ return pence ;
30+ }
31+
32+ console . log ( `£${ convertToPound ( "399p" ) } .${ convertToPence ( "399p" ) } ` ) ;
You can’t perform that action at this time.
0 commit comments