This question has already been answered:
I need to fill the basket object with the goods objects and sum the basket cost with its method.
I did this:
let basket = { sumBasket: function() { let sum = 0; for(var prop in this) { if(prop != "sumBasket") { sum = sum + prop.count * prop.price; } } return sum; } }; let smartphone = { price: 320, count: 2 }; let refrigerator = { price: 840, count: 1 }; let television = { price: 550, count: 3 }; function addToBasket(items) { return (basket = { ...basket, ...items }); }; addToBasket({smartphone, refrigerator, television}); console.log(basket); basket.sumBasket(); console.log(basket.sum); But my sum is NaN , since prop.count and prop.price are undefined
I guess I do not correctly refer to the properties of the goods. Help as needed?