Skip to content

Commit 253c6fc

Browse files
committed
Generate receipt by destructuring order items and calculating totals
1 parent 48d8171 commit 253c6fc

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,21 @@ let order = [
66
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
77
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
88
];
9+
10+
console.log("QTY ITEM TOTAL");
11+
12+
let total = 0;
13+
14+
order.forEach((product) => {
15+
const { itemName, quantity, unitPricePence } = product;
16+
17+
const price = unitPricePence / 100;
18+
const lineTotal = quantity * price;
19+
total += lineTotal;
20+
21+
console.log(
22+
`${quantity} ${itemName.padEnd(18)} ${lineTotal.toFixed(2)}`
23+
);
24+
});
25+
26+
console.log(`\nTotal: ${total.toFixed(2)}`);

0 commit comments

Comments
 (0)