Advertisement
bebo231312312321

Untitled

Mar 1st, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. class Storage {
  2. constructor(capacity) {
  3. this.capacity = capacity;
  4. this.storage = [];
  5. this.totalCost = 0;
  6. }
  7.  
  8. addProduct(product) {
  9. this.storage.push(product);
  10. this.capacity -= product.quantity;
  11. this.totalCost += product.price * product.quantity;
  12. }
  13.  
  14. getProducts() {
  15. return this.storage.map((product) => JSON.stringify(product)).join('\n');
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement