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 6750303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:47:30+00:00 2026-05-26T12:47:30+00:00

So far I created an array with 11 images, initialized the counter, created a

  • 0

So far I created an array with 11 images, initialized the counter, created a function, created a for loop but here is where I get lost. I looked at examples and tutorial on the internet and I can see the code is seeming simple but I’m not getting something basic here. I don’t actually understand how to call the index for the images. Any suggestions. Here is the code.

 <script type="text/javascript">
 var hammer=new Array("jackhammer0.gif",
                "jackhammer1.gif",
                "jackhammer2.gif",
                "jackhammer3.gif",
                "jackhammer4.gif",
                "jackhammer5.gif",
                "jackhammer6.gif",
                "jackhammer7.gif",
                "jackhammer8.gif",
                "jackhammer9.gif",
                "jackhammer10.gif")
 var curHammer=0;

 var numImg = 11;
 function getHammer() {

   for (i = 0; i < hammer.length; i++)
   {
     if (curHammer < hammer.length - 1) {
       curHammer = curHammer +1;
       hammer[i] = new Image();
       hammer[i].src="poses/jackhammer" +(i+1) + ".gif";

       var nextHammer = curHammer + 1;
       nextHammer=0;
       {
       }
     }
   }
 }


 setTimeout("getHammer()", 5000);

 </script>
</head>
 <body onload = "getHammer()";>
 <img id="jack" name="jack" src = "poses/jackhammer0.gif" width= "100" height ="113" alt =   "Man      and Jackhammer" /><br/>
 <button id="jack" name="jack" onclick="getHammer()">Press button</button>
  • 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-05-26T12:47:31+00:00Added an answer on May 26, 2026 at 12:47 pm

    Following on what Paul, said, here’s an example of what should work:

    var hammer=["jackhammer0.gif","jackhammer1.gif","jackhammer2.gif","jackhammer3.gif",
        "jackhammer4.gif","jackhammer5.gif","jackhammer6.gif","jackhammer7.gif",
        "jackhammer8.gif","jackhammer9.gif","jackhammer10.gif"];
    
    var curHammer=0;
    
    function getHammer() {
        if (curHammer < hammer.length) {
            document.getElementById("jack").src= "poses/" + hammer[curHammer];
            curHammer = curHammer + 1;
        }
    }
    
    setTimeout("getHammer()", 5000);
    

    The big missing element is that you need to call getElementById(“jack”) to get a reference to the DOM Image so that you can change it’s source. If you’re using jQuery or most other JS frameworks, just type $(“#jack”) to accomplish the same.

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

Sidebar

Related Questions

I need to load an array of images in Javascript, but I want to
I am trying the create a loop to extract data from an array created
As far as I know, only the convenience methods return created objects with an
I'm new to usercontrols, having only created one so far, so bear with me.
In JavaFx i can easy create animations, moving pieces etc., but as far as
I'm trying to define variables within a loop. I'll drop the code here and
I have created an attribute that accepts a (params) array in its constructor. internal
I just wrote a delegate method, that shall return an array, I've created inside
I need to get images along with other data (very similar to email with
I have a jQuery function that finds all the images nested in a container

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.