File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Sprint-1/destructuring/exercise-3 Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,23 @@ let order = [
66 { itemName : "Hot Coffee" , quantity : 2 , unitPricePence : 100 } ,
77 { itemName : "Hash Brown" , quantity : 4 , unitPricePence : 40 } ,
88] ;
9+
10+ // Print the receipt header
11+ console . log ( "QTY ITEM TOTAL" ) ;
12+
13+ // Initialize total cost
14+ let totalCost = 0 ;
15+
16+ // Loop through the order and log each item
17+ order . forEach ( ( { itemName, quantity, unitPricePence } ) => {
18+ const totalItemCost = ( unitPricePence * quantity ) / 100 ; // Convert pence to pounds
19+ totalCost += totalItemCost ; // Add to total cost
20+
21+ // Log the item details with proper formatting
22+ console . log (
23+ `${ quantity . toString ( ) . padEnd ( 8 ) } ${ itemName . padEnd ( 20 ) } ${ totalItemCost . toFixed ( 2 ) } `
24+ ) ;
25+ } ) ;
26+
27+ // Log the total cost
28+ console . log ( `\nTotal: ${ totalCost . toFixed ( 2 ) } ` ) ;
You can’t perform that action at this time.
0 commit comments