+ 2

[Solved] What's wrong in this code?

The ball isn't bouncing. https://code.sololearn.com/W5WEzg9a5bre/?ref=app

13th Jun 2021, 5:09 AM
Shobhit :)
Shobhit :) - avatar
4 Réponses
+ 2
well, I cannot guess what you really want to do... anyway I've modified your code to make the ball move on click (once): https://code.sololearn.com/Wcuvd6b51N59/?ref=app
13th Jun 2021, 5:42 AM
visph
visph - avatar
+ 3
there's no 'pos' css property... (you're trying to assign it through 'ball.style.pos') anyway, you get an error if you click on the ball, because getElementsByClassName doesn't return an element reference but an array like of element matching the class name (notice the 's' at element in the method name)... rather use document.querySelector(".ball") ;P but don't forgot the dot in front of the class name: this method expect a query string in css selector format as argument ^^ however, you cannot control the position of an element if you doesn't use the 'position' css propery on it with a value other than default 'static'... if positionned, then you could control its position through left/right/top/bottom css properties (don't use two on one side: this will affect the width and/or height of the element...
13th Jun 2021, 5:28 AM
visph
visph - avatar
+ 1
visph can you please correct my code and share please
13th Jun 2021, 5:35 AM
Shobhit :)
Shobhit :) - avatar
+ 1
Thank you so much visph
13th Jun 2021, 5:43 AM
Shobhit :)
Shobhit :) - avatar