File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 11const penceString = "399p" ;
2-
2+ // 1. const penceString = "399p": initialises a string variable with the value "399p"
33const penceStringWithoutTrailingP = penceString . substring (
44 0 ,
55 penceString . length - 1
66) ;
7-
7+ //2. removes "P" from the string
88const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
9+ //3. Ensures the string is at least 3 characters long by adding 0 to the start
910const pounds = paddedPenceNumberString . substring (
1011 0 ,
1112 paddedPenceNumberString . length - 2
1213) ;
13-
14+ //4. Extracts everything except the last 2 digits of paddedPenceNumberString
1415const pence = paddedPenceNumberString
1516 . substring ( paddedPenceNumberString . length - 2 )
1617 . padEnd ( 2 , "0" ) ;
17-
18+ //5. takes the last 2 digits as the pence from paddedPenceNumberString
1819console . log ( `£${ pounds } .${ pence } ` ) ;
20+ //6. Prints the formatted pounds-and-pence value
1921
2022// This program takes a string representing a price in pence
2123// The program then builds up a string representing the price in pounds
You can’t perform that action at this time.
0 commit comments