+ 3
How to make it alert only once
When I get a certain amount of point I want it to alert saying “you win”, but it alerts multiple times how do I fix it https://code.sololearn.com/Wh1cDbY7MU3n/?ref=app
7 Respostas
+ 7
When your game is finished, break out of the animation with cancelAnimationFrame. Therefore you need to keep track of the request id/ timestamp. See my comments in the JS tab.
https://code.sololearn.com/Wly4s39w741I/?ref=app
+ 3
I didn't consider multiple levels! Mirielle
I assumed that there was only 1 level (for now) and reaching the points would be the ending state. That's why I approached it by just "cleaning up everything"...
+ 1
Lisa Exactly 👍
0
Wow awesome game
0
chase warren
If score is always 5, alert will always be called. That's why your game is locked up with the alert.
Alternatively, if you want to keep playing, you could just reset your variables.
Change the last part to this:
if (score >= 5) {
alert("you win")
score = 0
t = Date.now()
dir = 0
}