0
Why isn't not moving the variable square
2 Réponses
+ 2
you should not use the id to style the square. You will end up with a bunch of duplicated ids. id should be unique. use class to style the square.
also, after updating the x and y value,
this.y += this.dy
the style should also be updated to reflect the changes. This is what makes the element move.
this.square.style.top = this.y+"px";
that's why you should maybe use
this.square
instead of var square to create element.
also, try not to use var. it makes the variables global. use let instead.
I played around with your code:
https://code.sololearn.com/WzrcGtRUaVxd/?ref=app
https://code.sololearn.com/WzX7fbKDsK37/?ref=app
+ 4
Leonard Function "update" is incrementing the increment itself, instead of the actual square position:
this.dy += this.y