title: TypeError: Cannot read properties of undefined while using getter js
body: <p>I built two classes, a product with name and price and a shopping cart for an array of products; for the ShoppingCart get totPrice method I'm using the reduce() function on the array cart of the constructor, but I'm always getting the error above and I don't get why.</p>
  <pre><code>class Product {
      constructor(name,price) {
          this.name = name;
          this.price = price;
      }
      toString() {
          console.log(this.name + ' - ' + this.price);
      }
  }
  
  class ShoppingCart {
      constructor(cart) {
          this.cart = cart;
      }
      get totPrice() {
          return this.cart.reduce((el1,el2) =&gt; {el1.price + el2.price});
      }
      addProd = function(prod) {
          this.cart.push(prod);
          this.cart.totPrice += prod.price;
          if(this.cart.length &gt;= 5){
              this.totPrice = this.totPrice * 0.9;
          }
          if(this.cart.filter(tmp =&gt; tmp.name === prod.name).length % 4 === 0){
              this.totPrice -= prod.price;
          }
      }
      removeProd = function(prod) {
          let i = this.cart.findIndex(el =&gt; {prod.name === el.name});
          this.cart.splice(i,1);
          console.log(`The product ${prod.name} has been removed from your shopping cart`);
      }
  } 
  
  let prod1 = new Product('Apple',15);
  
  let prod2 = new Product('Banana',20);
  
  let prod3 = new Product('Melon',25);
  
  let shopCart = new ShoppingCart([prod1,prod2,prod3]);
  
  console.log(shopCart.totPrice);
  </code></pre>