Plz help fix the bug | Sololearn: Learn to code for FREE!

0

3 Answers

New Answer

0

The problem is that u are change the canvas width/height on every loop inside setInterval(). This causes it to clear it everytime, effectively allowing only one rect to be shown since the other gets cleared. Move ur canvas/ctx initialization to the onload() so u only do this once. Also i would suggest to use requestAnimationFrame() instead of setInterval() for animating things

0

0

https://code.sololearn.com/WUFXZte5k2Qw/?ref=app