addEventListener (Two consecutive click Events)

if I have a class method that has a ‘click’ addEventListener that calls another method with a click event how do I make it so they are two distinct/separate clicks? For example:

pickUp() {
upcard.addEventListener('click', () => {
this.playerDiscard()
...

above the user clicks on the card they’re adding to their hand and the other method looks like this:

playerDiscard(){
playerCardSlot1.addEventListener('click', this.clickHandler())
playerCardSlot2.addEventListener('click', this.clickHandler())
}

I 'm assuming the first click event is triggering the playerDiscard() click event (playerCardslot1) however my problem is that the user should be able to click again to select whatever playerCardSlot they want to discard. Should I be adding a conditional statement above the playerDiscard event listeners or just remove the pickUp event listener? I have read a lot of documentation online, but am still not sure what to do. I would greatly appreciate some advice here. Thank you again.

I think we need to see your entire code base in order to give you any help. Do you have this in github or something similar?

Hey Bruce, thank you for the response. It’s the Euchre-Project in my GitHub linked here: evanvacchi · GitHub

It’s the click event for the pickUp() and playerDiscard() functions that go in tandem. Just FYI I am newer to coding, and I know that my code is probably messier than a normal person’s I am doing this project to add to my portfolio.

I noticed that if I take the () away from the clickHandler function in the EventListener it stops the event from running, however with the parentheses my program runs without letting the user click a second time.

I appreciate any and all help! Much Obliged, Evan

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.