Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class Storage {
  2. constructor(cap) {
  3. this.capacity = cap,
  4. this.storage = []
  5. this.totalCost = 0;
  6. this.addProduct = (p) => {
  7. let arr = p;
  8. this.capacity -= arr.quantity;
  9. this.totalCost += arr.price * arr.quantity;
  10. this.storage.push(p)
  11. }
  12. this.getProducts = () => {
  13. let temp = '';
  14. for (let v of this.storage) {
  15. console.log(JSON.stringify(v))
  16. }
  17. }
  18. }
  19. }
  20.  
  21.  
  22. let productOne = { name: 'Cucamber', price: 1.50, quantity: 15 };
  23. let productTwo = { name: 'Tomato', price: 0.90, quantity: 25 };
  24. let productThree = { name: 'Bread', price: 1.10, quantity: 8 };
  25. let storage = new Storage(50);
  26. storage.addProduct(productOne);
  27. storage.addProduct(productTwo);
  28. storage.addProduct(productThree);
  29. storage.getProducts();
  30. console.log(storage.capacity);
  31. console.log(storage.totalCost);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement