1. A shopping cart
Real apps keep arrays of objects: each item in a cart is an object, and the cart is an array of them.
cart[0].nameis the first item’s namefor (const item of cart) { ... }visits each object; inside, useitem.priceanditem.qty
Wrap the work in a function that takes the cart as a parameter — then it works for any cart.
const order = [
{ name: "Idli", price: 40, qty: 2 },
{ name: "Filter coffee", price: 25, qty: 1 },
];
for (const item of order) {
console.log(`${item.name}: ₹${item.price * item.qty}`);
}
Challenge: Kirana cart total
Complete cartTotal(items) so it returns the sum of price × qty for every item. For the given cart it returns 1110, and for an empty cart [] it returns 0. Then print Cart total: ₹1110.