File tree Expand file tree Collapse file tree
Sprint-1/3-mandatory-interpret
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const penceString = "399p" ;
1+ // const penceString = "399p";
22
3- const penceStringWithoutTrailingP = penceString . substring (
4- 0 ,
5- penceString . length - 1
6- ) ;
3+ function toPounds ( penceString ) {
4+ const penceStringWithoutTrailingP = penceString . substring (
5+ 0 ,
6+ penceString . length - 1
7+ ) ;
78
8- const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
9- const pounds = paddedPenceNumberString . substring (
10- 0 ,
11- paddedPenceNumberString . length - 2
12- ) ;
9+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
10+ const pounds = paddedPenceNumberString . substring (
11+ 0 ,
12+ paddedPenceNumberString . length - 2
13+ ) ;
1314
14- const pence = paddedPenceNumberString
15- . substring ( paddedPenceNumberString . length - 2 )
16- . padEnd ( 2 , "0" ) ;
15+ const pence = paddedPenceNumberString
16+ . substring ( paddedPenceNumberString . length - 2 )
17+ . padEnd ( 2 , "0" ) ;
1718
18- console . log ( `£${ pounds } .${ pence } ` ) ;
19+ let poundPence = `£${ pounds } .${ pence } ` ;
20+
21+ return poundPence ;
22+ }
23+ console . log ( toPounds ( "223p" ) ) ;
24+
25+ // console.log(`£${pounds}.${pence}`);
1926
2027// This program takes a string representing a price in pence
2128// The program then builds up a string representing the price in pounds
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 ( penceString ) {
9+ const penceStringWithoutTrailingP = penceString . substring (
10+ 0 ,
11+ penceString . length - 1
12+ ) ;
13+
14+ const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
15+ const pounds = paddedPenceNumberString . substring (
16+ 0 ,
17+ paddedPenceNumberString . length - 2
18+ ) ;
19+
20+ const pence = paddedPenceNumberString
21+ . substring ( paddedPenceNumberString . length - 2 )
22+ . padEnd ( 2 , "0" ) ;
23+
24+ let poundPence = `£${ pounds } .${ pence } ` ;
25+
26+ return poundPence ;
27+ }
28+ console . log ( toPounds ( "223p" ) ) ;
29+ console . log ( toPounds ( "43p" ) ) ;
30+ console . log ( toPounds ( "129p" ) ) ;
You can’t perform that action at this time.
0 commit comments