File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 1- const penceString = "399p" ;
1+ const penceString = "1399p" ; // stores the price in pence as a string with a trailing 'p'
22
33const penceStringWithoutTrailingP = penceString . substring (
44 0 ,
55 penceString . length - 1
6- ) ;
6+ ) ; // removes the trailing 'p' from the string to isolate the numeric part
77
88const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
99const pounds = paddedPenceNumberString . substring (
1010 0 ,
1111 paddedPenceNumberString . length - 2
12- ) ;
12+ ) ; // extracts the pounds part by taking all but the last two characters
1313
1414const pence = paddedPenceNumberString
15- . substring ( paddedPenceNumberString . length - 2 )
16- . padEnd ( 2 , "0" ) ;
15+ . substring ( paddedPenceNumberString . length - 2 ) // extracts the last two characters as the pence part
16+ . padEnd ( 2 , "0" ) ; // ensures the pence part is two digits by padding with '0' if necessary
1717
18- console . log ( `£${ pounds } .${ pence } ` ) ;
18+ console . log ( `£${ pounds } .${ pence } ` ) ; // outputs the formatted price in pounds and pence
1919
2020// This program takes a string representing a price in pence
2121// The program then builds up a string representing the price in pounds
You can’t perform that action at this time.
0 commit comments