File tree Expand file tree Collapse file tree
Sprint-2/3-mandatory-interpret Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ const penceString = "399p";
22
33const penceStringWithoutTrailingP = penceString . substring (
44 0 ,
5- penceString . length - 1
5+ penceString . length - 1 ,
66) ;
77
88const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
99const pounds = paddedPenceNumberString . substring (
1010 0 ,
11- paddedPenceNumberString . length - 2
11+ paddedPenceNumberString . length - 2 ,
1212) ;
1313
1414const pence = paddedPenceNumberString
@@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`);
2525
2626// To begin, we can start with
2727// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+ // 2. Removes the trailing "p" from penceString, changing "399p" to "399".
29+ // 3. Pads the pence string with leading zeros so it has at least 3 characters.
30+ // 4. Extracts all digits except the last two to get the pounds part of the price.
31+ // 5. Extracts the last two digits to get the pence part and ensures it has two digits.
32+ // 6. Formats the pounds and pence as a price and prints it to the console.
You can’t perform that action at this time.
0 commit comments