Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Storage {
- constructor(capacity) {
- this.capacity = capacity;
- this.storage = [];
- }
- addProduct(product) {
- this.storage.push(product);
- this.capacity -= product.quantity;
- }
- getProducts() {
- const productList = [];
- this.storage.forEach((element) => {
- console.log(JSON.stringify(element));
- productList.push(JSON.stringify(element));
- });
- return productList.join('\n');
- }
- get totalCost() {
- let totalPrice = 0;
- this.storage.forEach((element) => {
- totalPrice += element.price * element.quantity;
- });
- return totalPrice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment