+ 2

Why it generates infinite alerts after clicking the play button twice?

Hi, I was working on a simple game with javascript which I named "catch the murgi". Logic is quite simple, when the chicken enters inside the box, you just click on it to score! But, there are some problems and one of them is which I asked this question for. The problem is, when you press the play button twice before the game is over, it just generates alerts one after another and you can't exit from it without closing the whole app and opening it again. Please help me fix this and let me know the reason. Code link: https://code.sololearn.com/WsKL2tE2vqFW/?ref=app [NB: murgi == chicken ;)]

28th Jul 2020, 8:31 AM
Mahdee Mohammad
Mahdee Mohammad - avatar
5 Answers
+ 3
Now i corrected it Add Boolean, so user can't call the same function multiple times, hope you understand https://code.sololearn.com/WRqMjVwRNmyS/?ref=app
28th Jul 2020, 9:03 AM
v@msišŸ˜‰
v@msišŸ˜‰ - avatar
+ 2
Add a document.getElementById("btn).style.display = "none"; In your matha function. And a document.getElementById("btn).style.display = "block"; In your gameover function
28th Jul 2020, 8:49 AM
Nor'wester šŸŒŖļø šŸ‡§šŸ‡© (INACTIVE)
Nor'wester šŸŒŖļø šŸ‡§šŸ‡© (INACTIVE) - avatar
+ 2
Wait that's not solved its created another problem, after catching murgi it not running šŸ¤Ø Edit: OK, now it's fixed
28th Jul 2020, 9:12 AM
v@msišŸ˜‰
v@msišŸ˜‰ - avatar
+ 1
thank you so much everyone! But I will be very happy if someone tells me what was the reason behind that?
28th Jul 2020, 10:13 AM
Mahdee Mohammad
Mahdee Mohammad - avatar
+ 1
when one function is in progress and calling it again gives multiple values to same variable at same time, this cause some unexpected output. But I don't why it going infinite timesšŸ¤”
28th Jul 2020, 12:16 PM
v@msišŸ˜‰
v@msišŸ˜‰ - avatar