File tree Expand file tree Collapse file tree
Sprint-1/destructuring/exercise-3 Expand file tree Collapse file tree 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+ function orderReceipt ( orderItems ) {
11+ const totalList = [ ] ;
12+ for ( const item of orderItems ) {
13+ const { itemName, quantity, unitPricePence } = item ;
14+
15+ const total = ( ( quantity * unitPricePence ) / 100 ) . toFixed ( 2 ) ;
16+ totalList . push ( total ) ;
17+ const itemInfo = console . log ( ` ${ quantity } ${ itemName } ${ total } ` ) ;
18+ }
19+
20+ const grandTotal = totalList . reduce ( ( accumulator , current ) => {
21+ const totalCost = Number ( accumulator ) + Number ( current ) ;
22+ return totalCost ;
23+ } , 0 ) ;
24+ const finalBill = grandTotal . toFixed ( 2 ) ;
25+ console . log ( `Total:${ finalBill } ` ) ;
26+ }
27+
28+ orderReceipt ( order ) ;
You can’t perform that action at this time.
0 commit comments