Skip to content

Commit 3e0c968

Browse files
committed
ex-3-print-receipt
1 parent 269406b commit 3e0c968

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Sprint-1/destructuring/exercise-3/exercise.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)