File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +23
-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 ( penceStr ) {
9+ const penceStrWithoutTrailingP = penceStr . substring ( 0 , penceStr . length - 1 ) ;
10+ const paddedPenceNumberString = penceStrWithoutTrailingP . padStart ( 3 , "0" ) ;
11+ const pounds = paddedPenceNumberString . substring (
12+ 0 ,
13+ paddedPenceNumberString . length - 2
14+ ) ;
15+ const pence = paddedPenceNumberString
16+ . substring ( paddedPenceNumberString . length - 2 )
17+ . padEnd ( 2 , "0" ) ;
18+
19+ return `£${ pounds } .${ pence } ` ;
20+ }
21+
22+ console . log ( toPounds ( "123p" ) ) ; // £1.23
23+ console . log ( toPounds ( "1002p" ) ) ; // £10.02
24+ console . log ( toPounds ( "0p" ) ) ; // £0.00
25+ console . log ( toPounds ( "99p" ) ) ; // £0.99
26+ console . log ( toPounds ( "250p" ) ) ; // £2.50
27+ console . log ( toPounds ( "7p" ) ) ; // £0.07
28+ console . log ( toPounds ( "48p" ) ) ; // £0.48
29+ console . log ( toPounds ( "53647868p" ) ) ; // £536478.68
You can’t perform that action at this time.
0 commit comments