Image doesn’t get hidden

I am developing pacman since its a Lab Assignment. And I try to hide food(image) when pacman reaches it. This is the code that I used which is working :

if((parseInt(image1.style.left)>=(parseInt(s1.style.left))) && (parseInt(image1.style.left)<=(parseInt(s1.style.left)+100)) && 
        (parseInt(image1.style.top)+30>=(parseInt(s1.style.left) && parseInt(image1.style.top)+30<=(parseInt(s1.style.left)+100)))) 

    {var e= document.getElementById('s1');

    e.style.visibility='hidden';
    }
<img id="s1" src="s.gif" style="position: fixed; top:50; left:100" />

Now the problem is that I’m using the exact same code for another food but it is not working. Here it is :

<img id="s5" src="s.gif" style="position: fixed; top:150; right:700" />
if((parseInt(image1.style.left)>=(parseInt(s5.style.right))) && (parseInt(image1.style.right)<=(parseInt(s5.style.right)+100)) && 
        (parseInt(image1.style.top)+30>=(parseInt(s5.style.right) && parseInt(image1.style.top)+30<=(parseInt(s5.style.right)+100))))   

    {var e2= document.getElementById('s5');
document.write("eee");
    e2.style.visibility='hidden';
    }


Source: html

Leave a Reply