Skip to content

Commit 8d82196

Browse files
committed
Implemented takeout order receipt with destructuring and formatted totals
1 parent b07cf4e commit 8d82196

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

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

0 commit comments

Comments
 (0)