const monster = document.getElementById('monster') let x = window.innerWidth / 2 let y = window.innerHeight / 2 let dx = 2.5 let dy = 2.5 function init(){ monster.style.top = + "px" monster.style.left = window.innerWidth / 2 + "px" movement() } function movement(){ if( x > window.innerWidth - 100 || x <= 0 ){ dx *= -1; } if( y > (window.innerHeight - 100) || y <= 100 ){ dy *= -1; } x += dx y += dy monster.style.top = y + "px" monster.style.left = x + "px" requestAnimationFrame(movement) } init()