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 55
66// You should call this function a number of times to check it works for different inputs
77
8- function toPounds ( penceAmount ) {
9-
10- const penceStringWithoutTrailingP = String ( penceAmount ) ;
8+ function toPounds ( penceString ) {
9+ const penceStringWithoutTrailingP = penceString . substring (
10+ 0 ,
11+ penceString . length - 1
12+ ) ;
1113
1214 const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
1315
1416 const pounds = paddedPenceNumberString . substring (
1517 0 ,
1618 paddedPenceNumberString . length - 2
17- ) ;
19+ ) ;
1820
1921 const pence = paddedPenceNumberString
20- . substring ( paddedPenceNumberString . length - 2 ) . padEnd ( 2 , "0" ) ;
22+ . substring ( paddedPenceNumberString . length - 2 )
23+ . padEnd ( 2 , "0" ) ;
2124
2225 return `£${ pounds } .${ pence } ` ;
2326}
2427
25- console . log ( toPounds ( 399 ) ) ;
26- console . log ( toPounds ( 50 ) ) ;
27- console . log ( toPounds ( 1729 ) ) ;
28- console . log ( toPounds ( 5 ) ) ;
28+ console . log ( toPounds ( "399p" ) ) ;
29+ console . log ( toPounds ( "50p" ) ) ;
30+ console . log ( toPounds ( "1729p" ) ) ;
31+ console . log ( toPounds ( "5p" ) ) ;
You can’t perform that action at this time.
0 commit comments