+ 1

javascript animation&events problem

this ball should move in the square and on click it stops & on the second click it moves till now everything is good but when you click it on the third time nothing happens on the fourth time it goes faster so how can I fix it? https://code.sololearn.com/W0xPhz40IRY3/#html

10th Aug 2020, 1:15 PM
Youssef Ashraf
Youssef Ashraf - avatar
3 Réponses
+ 2
Youssef Ashraf After the first click, your code is creating extra timers but not clearing them. This is the reason the ball speed increases and does not stop. You need to assign the setInterval() invoked at line 23 to the variable t.
10th Aug 2020, 2:05 PM
ODLNT
ODLNT - avatar
+ 1
Thanks alot
10th Aug 2020, 2:08 PM
Youssef Ashraf
Youssef Ashraf - avatar
+ 1
You're welcome. ✌
10th Aug 2020, 2:11 PM
ODLNT
ODLNT - avatar