File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +18
-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 getPenceString ( penceString ) {
9+
10+ const penceStringWithoutTrailingP = penceString . substring ( 0 , penceString . length - 1 ) ;
11+ //removes p
12+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
13+ //puts zeros in front of number if less than 3 digits
14+ const pounds = paddedPenceNumberString . substring ( 0 , paddedPenceNumberString . length - 2 ) ;
15+ //removes last 2 digits to get pounds
16+ const pence = paddedPenceNumberString . substring ( paddedPenceNumberString . length - 2 ) . padEnd ( 2 , "0" ) ;
17+ //gets last 2 digits to get pence, if less than 2 digits adds zeros to end of string but shouldnt be less than 3
18+ //due to padStart above
19+ return `£${ pounds } .${ pence } ` ;
20+ // returns string with pounds and pence in correct format
21+ }
22+
23+ console . log ( getPenceString ( "399p" ) ) ;
24+ // tested with 123p 1200p 24589p 89p 9p and 0p
You can’t perform that action at this time.
0 commit comments