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 @@ -25,3 +25,20 @@ 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+
29+ 1. const penceString = "399p" // Stores "399p" in a variable called penceString so the program can work with the price.
30+ 2. const penceStringWithoutTrailingP = penceString . substring (
31+ 0 ,
32+ penceString . length - 1
33+ ) ; // Removes the "p" from the end of "399p", leaving "399"
34+ 3. const paddedPenceNumberString = penceStringWithoutTrailingP . padStart ( 3 , "0" ) ;
35+ //Adds a "0" at the start if there are less than 3 digits.
36+ 4. const pounds = paddedPenceNumberString . substring (
37+ 0 ,
38+ paddedPenceNumberString . length - 2 ) ; //gets the digits before the last two to find the pounds.
39+
40+ 5. const pence = paddedPenceNumberString
41+ . substring ( paddedPenceNumberString . length - 2 )
42+ . padEnd ( 2 , "0" ) ; //gets the last two digits to find the pence.
43+
44+ 6. console . log ( `£${ pounds } .${ pence } ` ) ; //Combines the pounds and pence and print the final price as £3.99
You can’t perform that action at this time.
0 commit comments