Click handler Reference Error function is not defined

I’ve created a slider with arrows for next and previous slides and it’s working.

I’m trying to hook up navigation dots like so:

{% for i in section.blocks %}
        - 

        {% endfor %}

But I’m getting a reference error.
I’m unable to add an event listener to the buttons in the js for some reason.
is there a better way to do it?