Advertisement
didkoslawow

Untitled

Feb 26th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.       const result = [];
  16.  
  17.       this.storage.forEach(product => {
  18.         result.push(JSON.stringify(product));
  19.       });
  20.       return result.join('\n');
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement