Помогите наладить работу Js кода

Пытаюсь добиться, чтобы метод считал сумму корзины.

const cart = {
      items: [
        {
          title: "Клавиатура",
          price: 1000,
          quantity: 2,
        },
        {
          title: "Мышь",
          price: 500,
          quantity: 2,
        },
        {
          title: "Монитор",
          price: 5000,
          quantity: 1,
        }
      ],
    
      totalPrice() {
        return this.items.reduce((sum, item) => {
          return sum + items.price * items.quantity;
        }, 0);
      },
    };
 

   console.log(totalPrice());

Ответы (1 шт):

Автор решения: splash58

в вызове card.totalPrice, в функции вместо items надо item

const cart = {
  items: [
    {
      title: "Клавиатура",
      price: 1000,
      quantity: 2,
    },
    {
      title: "Мышь",
      price: 500,
      quantity: 2,
    },
    {
      title: "Монитор",
      price: 5000,
      quantity: 1,
    }
  ],
  
  totalPrice() {
    return this.items.reduce((sum, item) => {
      return sum + item.price * item.quantity;
    }, 0);
  },
};
console.log(cart.totalPrice());

→ Ссылка