+ 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

19th Aug 2022, 9:01 AM
chase warren
7 Answers
+ 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
19th Aug 2022, 9:15 AM
Lisa
Lisa - avatar
+ 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"...
19th Aug 2022, 11:23 AM
Lisa
Lisa - avatar
+ 1
Lisa Exactly 👍
19th Aug 2022, 9:29 AM
SùñtÎsh
SùñtÎsh - avatar
0
Wow awesome game
20th Aug 2022, 3:11 AM
Bhadri Raj T
Bhadri Raj T - avatar
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 }
20th Aug 2022, 3:28 AM
Bob_Li
Bob_Li - avatar