nikolayneykov

Untitled

Mar 6th, 2019
159
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.quantity * product.price;
  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