Skip to content

Commit 764f28e

Browse files
committed
Print receipt with item totals and overall total using object destructuring
1 parent efa5ce8 commit 764f28e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ 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 totalCost = 0;
13+
14+
order.forEach(({ itemName, quantity, unitPricePence }) => {
15+
const itemTotal = (quantity * unitPricePence) / 100; // Convert pence to pounds/dollars
16+
totalCost += itemTotal;
17+
18+
// Format each line with spacing to match the expected output
19+
console.log(
20+
`${quantity} ${itemName.padEnd(18)}${itemTotal.toFixed(2)}`
21+
);
22+
});
23+
24+
console.log(`\nTotal: ${totalCost.toFixed(2)}`);

0 commit comments

Comments
 (0)