Café Orders
JavaScript
20 pts
Café Orders
Write a constructor Order(customer) that sets this.customer, an empty array this.items and this.total = 0. Add two methods on Order.prototype:
add(item, price)pushes the item name intoitemsand adds the price tototal,summary()returns text likeSelam: tea, cake = 50 Nakfa(usejoin(", ")).
Create an order for Selam (tea 15, cake 35) and one for Abel (coffee 20), and print both summaries. Every order must have its own items array. Expected output:
Selam: tea, cake = 50 Nakfa Abel: coffee = 20 Nakfa
Checklist
- Write the constructor
Order(customer). - Add
add(item, price); each order keeps its own items. - Add
summary(). - Print both summaries.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
