File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +20
-0
lines changed 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+ function toPounds ( penceToPound ) {
9+ const penceStringWithoutTrailingP = penceToPound . substring ( 0 , penceToPound . length - 1 ) ; // Remove the P at the end.
10+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ; // Make sure there 3 digits at least.
11+ const pounds = paddedPenceNumberString . substring (
12+ 0 ,
13+ paddedPenceNumberString . length - 2
14+ ) ; // get the pounds part( - the last two digits).
15+ const pence = paddedPenceNumberString
16+ . substring ( paddedPenceNumberString . length - 2 )
17+ . padEnd ( 2 , "0" ) ; // get the pence part( they should be 2 digits).
18+ return `£${ pounds } .${ pence } ` ; // The final format.
19+ }
20+ console . log ( toPounds ( "3990p" ) ) ;
21+ console . log ( toPounds ( "1500p" ) ) ;
22+ console . log ( toPounds ( "150p" ) ) ;
23+ console . log ( toPounds ( "100p" ) ) ;
24+ console . log ( toPounds ( "70p" ) ) ;
25+ console . log ( toPounds ( "50p" ) ) ;
26+ console . log ( toPounds ( "0p" ) ) ;
You can’t perform that action at this time.
0 commit comments