Skip to content

Commit c586205

Browse files
committed
exercise-3
1 parent 798da30 commit c586205

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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+
// Print the receipt header
11+
console.log("QTY ITEM TOTAL");
12+
13+
// Initialize total cost
14+
let totalCost = 0;
15+
16+
// Loop through the order and log each item
17+
order.forEach(({ itemName, quantity, unitPricePence }) => {
18+
const totalItemCost = (unitPricePence * quantity) / 100; // Convert pence to pounds
19+
totalCost += totalItemCost; // Add to total cost
20+
21+
// Log the item details with proper formatting
22+
console.log(
23+
`${quantity.toString().padEnd(8)}${itemName.padEnd(20)}${totalItemCost.toFixed(2)}`
24+
);
25+
});
26+
27+
// Log the total cost
28+
console.log(`\nTotal: ${totalCost.toFixed(2)}`);

0 commit comments

Comments
 (0)