I want to know if the first object is in the same position of the second object to alert a message.
I am trying to create a simple game to see if the falling object touches the object that I move with my keyboard to stop the game and write "game over".
var t = setInterval(move,50);
var b = document.getElementById("ball");
var u = document.getElementById('obj') ;
function move() {
var pob = parseInt(b.style.top);
if (pob + 30 >=350){
pob = 0;
var p = Math.floor(Math.random()*320);
b.style.left = p + "px";
}
pob += 10;
b.style.top=pob+"px";
var f = parseInt(b.style.top) ;
var box = parseInt(u.style.top);
if (f == box) {
alert("stop");
}
}