title: Passing the Eventlistener to the correct function in JS
body: <p>I have two buttons (each of them has a value which matches the id of a dish in the food menu) with two EventListeners. One button for adding something to a shopping cart and one button to remove something from the shopping cart. My problem is, that i cant figure out how to pass the Eventlistener to the correct class function. This is my code so far:</p>
  <pre><code>class Cart {
      
      constructor() {
          this.inhalt = [];
      }
  
      add(item) {
          this.inhalt.push(item);
          console.log(this.inhalt)
      }
  
      remove(item) {
          for (let i = 0; i &lt; this.inhalt.length; i++) {
              if (this.inhalt[i].id === item.id) {
                  this.inhalt.splice(i, 1);
                  console.log(this.inhalt)
              }
          }
      }
  
      sum() {
          let s = null;
          this.inhalt.price.forEach(element =&gt; {
              s += element
          });
          console.log(s)
      }
  }
  
  const myCart = new Cart();
  
  function getItem(type) {
      let item = null;
          for (let i=0; i&lt;speisekarte.length; i++) {
              if (speisekarte[i].id === this.value) {
                  item = speisekarte[i];
                  break;
              }
          }
          if (type == &quot;plus&quot;) {myCart.add(item)}
          else if (type == &quot;minus&quot;) {myCart.remove(item)};
  }
  
  let plus = document.querySelectorAll(&quot;.kaufen&quot;);   
  plus.forEach(el =&gt;{                             
      let type = &quot;plus&quot;; el.addEventListener(&quot;click&quot;, getItem(type));
  });
  
  let minus = document.querySelectorAll(&quot;.zurück&quot;);
  minus.forEach(el =&gt;{
      let type = &quot;minus&quot;; el.addEventListener(&quot;click&quot;, getItem(type));
  });
  </code></pre>