How do I 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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How to Build a Food Ordering App in a Machine Coding Interview
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.
Empty cart (show a message), no search results (show a message), quantity 0 (remove from cart), decimal prices, clear cart button, and checkout confirmation. These show production-readiness.
Still have questions?
Browse all our FAQs or reach out to our support team
