lundi 4 décembre 2017

Randomly remove image from game space without using class in JavaScript/jQuery

I am trying to have the Moles (little cubes in http://ift.tt/2jeISXH) randomly disappear form the #gamespace if they are not clicked on. They randomly appear between 0 - 2 seconds. The game is working on Firefox without this question addressed while including my attempt, but it is not working in JSFiddle.

 function addMole(){
        xPos=randPosX();
        yPos=randPosY();
        $("#gamespace").append('<img src="img/mole.png" style="top:'+xPos+'px; left:'+yPos+'px;" />');
        var r=Math.floor(Math.random()*(2000));
        t=setTimeout("addMole();", r);
        var count=0;
        var image='img src="img/mole.png"/'
        setTimeout("fadeOut()", 1000);
        function fadeOut(){
            $("div#gamespace").append("<image id='image"+count+"'></image>");
            count++;
            setTimeout("fadeOut()", 1000);
        };
    };//end mole

My instructor told us not to use a class and gave us this example. Obviously, I want to fadeOut instead of add anything. And I don't have any <p> tags. I just don't know what to put in their place. Or if I totally messed it up.

var count=0;
setTimeout("add()",$1000);
function add(){
$("div#div1").append("<p id='p"+count+"'></p>");
count++;
  setTimeout("add()",$1000);$}




Aucun commentaire:

Enregistrer un commentaire