+ 1

Console value is unexpected

The if-else switch isn't working as it expects to call p1 -> p2... https://code.sololearn.com/WW3BM46nLu9t/#js

20th Jul 2020, 2:20 AM
zexu knub
zexu knub - avatar
4 Antworten
+ 5
Elements can have multiple event listeners for the same event. addEventListener does not remove the previous functions(callbacks) that are waiting for the event triggering. When you "play()" you are adding a new function(and another,and another...) to be called when the user clicks. A way to solve this would be to call removeEventListener before adding a new one but that's ugly. Simply avoid calling addEventListener within your play function. I used a global variable to keep track of the current player and a loop to avoid code repetition: https://code.sololearn.com/W8eFWdcY2eVS/?ref=app Tip: Don't change your code while the question is unanswered. That makes things harder for your helpers😅.
20th Jul 2020, 3:54 AM
Kevin ★
+ 6
Hey, change that face. It's ok, this things have happened a lot to me too and to everyone. Keep practicing, you are doing a good job already and I'm sure you will be able to improve it. Feel free to keep inquiring if you have more doubts.
20th Jul 2020, 4:42 AM
Kevin ★
+ 1
Kevin ★ Thank You ;)
20th Jul 2020, 4:46 AM
zexu knub
zexu knub - avatar
0
Kevin ★ i was trying to make it work somehow but thank you so much it makes sense now. And also thank you for clearing the repetition. 😓
20th Jul 2020, 4:25 AM
zexu knub
zexu knub - avatar