Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:48:35+00:00 2026-06-04T08:48:35+00:00

I have an array call Predatorlist storing <div id=Predator1><img src=’jef-frog.gif’ width=’50’></div> And I declared

  • 0

I have an array call “Predatorlist” storing

 <div id="Predator1"><img src='jef-frog.gif' width='50'></div>

And I declared a var to store the “Predator” and attached the ID.

var speciesType = 'Predator' + document.getElementById('amount').value; 

And I have an Input button ::

 <INPUT type="button" value="Play" onClick="javascript:runItem('Predator') ;"> 

May I know what item I should pass in for the following function to capture and produce as what is required in the input button. “Javascript:runItem(‘Predator’);?

function runItem(Predatorlist) {
     var item1 = $("#"+speciesType),cycle1;
     /* Set a the starting position to be random by editing the css */
     $(item1).css("left", startItem1X+"px");
     $(item1).css("top", startItem1Y+"px");

     //$("<img src='jef-frog.gif' width='50'>").appendTo("div#Predator");

     /* Cycle1 and Cycle2 variables allow infinite loop */ 
     (cycle1 = function() {
      var m = randomRange(50,100);
      var n = randomRange(75,150);
      item1.animate({left:'+='+n},2000);
      item1.animate({left:'+='+m, top:'+='+m}, 2000)
      item1.animate({left:'-='+m, top:'+='+m}, 2000)
      item1.animate({left:'-='+n},2000);
      item1.animate({top:'-='+n},2000,cycle1)
          })();

         alert(speciesType);
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:48:36+00:00Added an answer on June 4, 2026 at 8:48 am
    var item1 = $("#"+speciesType)
    $(item1). //something...
    

    This doesnt look right, you should only give a string into a jQuery object, it makes the code far more readable than passing the enire object in there. So, the above lines should become either

    var item1 = "#"+speciesType
    $(item1). //something...
    

    or

    var item1 = $("#"+speciesType)
    item1. //something...
    

    Next, I would use a setInterval for the animation loop, because you cannot stop it like you have it now, and it makes the code much cleaner.


    Finally, for your predators: Do you need something like the following, that appends code to the body of the document?

    for(var i in predatorList) {
      $('body').append('<div id="'+predatorList[i]+'"><img src="img/pred.png"></div>');
    }
    

    For more questions, please comment, I found the question hard to understand, so my answer might not be what you mean.


    EDIT 2:

    See the code (working): http://jsfiddle.net/sREEw/3/

    What am I doing?

    On an addition of a predator:

    • Add the div to the body
    • Give the div an id of the current number of predators
    • set an animation loop, but first cancelling the first if it was already running. In the loop we update every predator there is
    • Increase the num, so the next predator will have a new ID

    On a removal of a predator:

    • Decrease the num by 1 for easier calculations
    • Remove the predator from the body
    • stop the interval if needed

    As you can see, all I am saving in variables is the current number of predators, and the interval ID, so I can stop the loop if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of objects . Each object has an attribute we'll call
I have a 2D array, call it A . I have two other 2D
I have an API call that returns a byte array. I currently stream the
I have some code which builds an array of date ranges. I then call
I have an array of users who are friends. Let us call this array:
I have a numpy array (we'll call it test) of ~286 x 181 x
I have an array, let's call it array and inside of the array I
i would like to have an array of objects in excel that call one
I have an array of UIView objects. I want to call - (NSArray *)filteredArrayUsingPredicate:(NSPredicate
I have an array of different elements stored from a previous selection, call it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.