File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
Sprint-1/destructuring/exercise-3 Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -7,22 +7,23 @@ let order = [
77 { itemName : "Hash Brown" , quantity : 4 , unitPricePence : 40 } ,
88] ;
99
10- // Print the receipt header
11- console . log ( "QTY ITEM TOTAL" ) ;
10+ // Define column spacing for consistent formatting
11+ const columnSpacing = 8 ;
12+
13+ // Print the receipt header with aligned columns
14+ console . log ( "QTY" . padEnd ( columnSpacing ) + "ITEM" . padEnd ( 20 ) + "TOTAL" ) ;
1215
13- // Initialize total cost
1416let totalCost = 0 ;
1517
16- // Loop through the order and log each item
1718order . forEach ( ( { itemName, quantity, unitPricePence } ) => {
1819 const totalItemCost = ( unitPricePence * quantity ) / 100 ; // Convert pence to pounds
19- totalCost += totalItemCost ; // Add to total cost
20+ totalCost += totalItemCost ;
2021
21- // Log the item details with proper formatting
22+ // Log each item's details with proper alignment
2223 console . log (
23- `${ quantity . toString ( ) . padEnd ( 8 ) } ${ itemName . padEnd ( 20 ) } ${ totalItemCost . toFixed ( 2 ) } `
24+ `${ quantity . toString ( ) . padEnd ( columnSpacing ) } ${ itemName . padEnd ( 20 ) } ${ totalItemCost . toFixed ( 2 ) } `
2425 ) ;
2526} ) ;
2627
27- // Log the total cost
28+ // Print the total cost at the end
2829console . log ( `\nTotal: ${ totalCost . toFixed ( 2 ) } ` ) ;
You can’t perform that action at this time.
0 commit comments