I am attempting to create a basic function that increments a counter when one of my list items is clicked on. However, I keep encountering an error message that says addEventListener is not a function.
This is how the HTML looks:
<ul class="boxes">
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
</ul>
The JavaScript portion is as follows:
var squares = document.getElementsByClassName('box');
function MyCounter(el){
this.turn = 0;
this.addClick = function() {
this.turn ++;
console.log(this.turn);
};
el.addEventListener('click', this.addClick(), false);
}
var c = new MyCounter(squares);
Does anyone have any suggestions on how to fix this issue?