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

  • Home
  • SEARCH
  • 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 4244424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:42:22+00:00 2026-05-21T03:42:22+00:00

I have just started looking at javascript so hopefully this will be something simple.

  • 0

I have just started looking at javascript so hopefully this will be something simple. I want to make a slideshow of images that plays automatically. This is very simple, and there are a few tutorials on it but for some reason I haven’t been able to get it to work. This is what I have:

var image1 = new Image();
var image2 = new Image(); 
var image3 = new Image();
image1.src = "images/website6.jpg";
image2.src = "images/website7.jpg";
image3.src = "images/sunset.jpg";
var images = new Array(
  "images/website6.jpg",
  "images/website7.jpg",
  "images/sunset.jpg"
);
setTimeout("delay(images,0)",2000);
function delay(arr,num){
  document.slide.src = arr[num % 3];
  var number = num + 1;
  setTimeout("delay(arr,number)",1000);
}

The image I’m trying to change has id slide. And I also have some evidence that it works. What happens is the first image loads. Then the second image loads (which means the original setTimeout call must be working). Then nothing happens. Which to me suggests it’s the recursion that isn’t working.

I am very familiar with recursion in other languages, so I think it must just be a syntax thing or something, but I can’t seem to figure it out. Thanks for any help.

  • 1 1 Answer
  • 1 View
  • 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-21T03:42:23+00:00Added an answer on May 21, 2026 at 3:42 am

    The problem is that when you pass in strings to be evaluated to the setTimeout call, the evaluation will be done (later, when it’s time to fire) in the global context. Thus, you’re way better off (for a lot of other reasons) passing in actual functions:

    setTimeout(function() { delay(images, 0); }, 2000);
    
    function delay(arr, num) {
      document.slide.src = arr[num % 3];
      setTimeout(function() { delay(arr, num + 1); }, 1000);
    }
    

    In more modern browsers, you can use the .bind() method for functions to create a function that’s pre-bound to something to be used as this:

    setTimeout(delay.bind({arr: images, num: 0}), 2000);
    
    function delay() {
      document.slide.src = this.arr[this.num % 3];
      setTimeout(delay.bind({arr: this.arr, num: this.num + 1}), 1000);
    }
    

    Six of one, half-dozen of the other, but just as an example that shows there are multiple ways to do things.

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

Sidebar

Related Questions

I have just started to learn Scala. I was looking for something in line
I have just started looking at JqueryMobile and want to know if the following
I have just started looking into jquerymobile, done simple samples using jquery.mobile-1.0a1 . I
I am just getting started couchdb and have been looking into writing couch apps.
I have just started using RSpec and I copied the very simple test on
I have just started looking into .net MVC and I really like it. There
Just started to play around with node.js, have some past experience with JavaScript but
I'm starting a new project that will be heavy on javascript and am looking
I just started looking into SQLite for the iPhone SDK. I have been looking
I just started looking into jQuery yesterday, before this I programmed in only PHP.

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.