File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Sprint-1/3-mandatory-interpret Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change 11const penceString = "399p" ;
2+ //initialises a string variable with the value "399p"
23
34const penceStringWithoutTrailingP = penceString . substring (
45 0 ,
56 penceString . length - 1
67) ;
8+ // declare a new var and assign penceString value without last character (p)/
79
810const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
11+ //declare a new variable and Make sure it is at least 3 digits long eg: 1 become 001.
12+
913const pounds = paddedPenceNumberString . substring (
1014 0 ,
1115 paddedPenceNumberString . length - 2
1216) ;
17+ //declare a new variable and assign the paddedPenceNumberString value without last two digit.
1318
1419const pence = paddedPenceNumberString
1520 . substring ( paddedPenceNumberString . length - 2 )
1621 . padEnd ( 2 , "0" ) ;
17-
22+ // pence= take the pound length and remove it and keep all rest digit and if the shorter than 2 digit add 0 until paddedPenceNumberString
23+ // .substring(paddedPenceNumberString.length - 2) becomes 2 digits
1824console . log ( `£${ pounds } .${ pence } ` ) ;
1925
2026// This program takes a string representing a price in pence
You can’t perform that action at this time.
0 commit comments