Hi there so i'm trying to create a bouncing ball using javascript and i need some help finishing it without using any complicated code this is the code that i have done:
https://codepen.io/messili-islem/pen/XWrjOja
i appreciate your help guys Thanks
var ball = document.getElementById('ball')
var ballObj = { x: 0, y: 0, dx: 1, dy: 1, size: 100 }
var x = 0
var y = 0
function movement () {
var id = setInterval(moveball, 1)
function moveball () {
function downleft () {
x++
y++
ball.style.top = x + 'px'
ball.style.left = y + 'px'
}
function upright () {
x--
y--
ball.style.top = x + 'px'
ball.style.left = y + 'px'
}
function downright () {
x++
y--
ball.style.top = x + 'px'
ball.style.left = y + 'px'
}
function upleft () {
x--
y++
ball.style.top = x + 'px'
ball.style.left = y + 'px'
}
downleft()
if (x == 400) {
clearInterval(id)
var id2 = setInterval(upleft, 1)
}
}
}