Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Storage {
- constructor(cap) {
- this.capacity = cap,
- this.storage = []
- this.totalCost = 0;
- this.addProduct = (p) => {
- let arr = p;
- this.capacity -= arr.quantity;
- this.totalCost += arr.price * arr.quantity;
- this.storage.push(p)
- }
- this.getProducts = () => {
- let temp = '';
- for (let v of this.storage) {
- console.log(JSON.stringify(v))
- }
- }
- }
- }
- let productOne = { name: 'Cucamber', price: 1.50, quantity: 15 };
- let productTwo = { name: 'Tomato', price: 0.90, quantity: 25 };
- let productThree = { name: 'Bread', price: 1.10, quantity: 8 };
- let storage = new Storage(50);
- storage.addProduct(productOne);
- storage.addProduct(productTwo);
- storage.addProduct(productThree);
- storage.getProducts();
- console.log(storage.capacity);
- console.log(storage.totalCost);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement