var velocity = 100;
var positionX = 0;
var ball = document.getElementById('ball');
function moveBall() {
var Xmin = 0;
var Xmax = 300;
positionX = positionX + velocity;
ball.style.left = positionX + 'px';
}
setInterval(moveBall, 100);
img {
position: absolute;
}
<img id="ball" width="150" height="150" src="https://tr.seaicons.com/wp-content/uploads/2016/11/Volleyball-Ball-icon.png"/>
I have declared my global variables, followed by a function to move the ball, then followed by a setInterval. However, I can't seem to figure the right way to reverse the ball that continuously moves to the right of my screen until no longer visible. Is it a matter of a type of reverse method or setting up conditions?