Facebook Pixel
How to Build a Food Ordering App in a Machine Coding Interview

How do you calculate the cart total in a food ordering app?

The answer

Sum price * quantity for each item in the cart: Object.entries(cart).reduce((sum, [id, qty]) => { const item = menu.find(m => m.id === parseInt(id)); return sum + item.price * qty; }, 0).

More FAQs in How to Build a Food Ordering App in a Machine Coding Interview

Create a menu array, a cart object (item ID to quantity), search and filters. Render the filtered menu and cart sidebar. Handle add/remove from cart, quantity changes, and total calculation. Handle empty cart and no results. This is a real Swiggy interview question.

Use an object mapping item ID to quantity: cart = { 1: 2, 3: 1 }. addToCart increments the quantity. removeFromCart deletes the key. Calculate total by summing price * qty for each item in the cart.

Filter the menu array based on search query (name includes query), veg/non-veg flag, category, and price range. Re-render the menu on every filter change. Show 'No items found' if the filtered list is empty.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.