File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 11const penceString = "399p" ;
2-
2+ // it creates a string representing a price in pence,the p at the end indicates the unit.
33const penceStringWithoutTrailingP = penceString . substring (
44 0 ,
55 penceString . length - 1
66) ;
7-
7+ // it removes the trailing "p" from the penceString, leaving only the numeric part of the string.
88const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
9+ //Insure the numeric string has at least 3 characters, padding it with 0 if needed.
910const pounds = paddedPenceNumberString . substring (
1011 0 ,
1112 paddedPenceNumberString . length - 2
1213) ;
13-
14+ // Takes all digits except the last two to represent the pounds part of the price.
1415const pence = paddedPenceNumberString
1516 . substring ( paddedPenceNumberString . length - 2 )
1617 . padEnd ( 2 , "0" ) ;
17-
18+ // Takes the last two digits to represent the pence part of the price, ensuring it has two characters.
1819console . log ( `£${ pounds } .${ pence } ` ) ;
20+ // it logs the final price in pounds and pence format : "£3.99"
21+
22+
1923
2024// This program takes a string representing a price in pence
2125// The program then builds up a string representing the price in pounds
You can’t perform that action at this time.
0 commit comments