There was an error while loading. Please reload this page.
1 parent b07cf4e commit 8d82196Copy full SHA for 8d82196
1 file changed
Sprint-1/destructuring/exercise-3/exercise.js
@@ -6,3 +6,22 @@ let order = [
6
{ itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 },
7
{ itemName: "Hash Brown", quantity: 4, unitPricePence: 40 },
8
];
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