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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:10:51+00:00 2026-06-06T18:10:51+00:00

I am beginning to hate objects in javascript. Every time I have error and

  • 0

I am beginning to hate objects in javascript.

Every time I have error and I fix it, a new error appears, and so on.
Can you please take a look at the following code and tell me what’s wrong ?

problem message:
“this.Images is undefined”
and more errors also

HTML File

<div id="SlideShow" >
   <img id="img" src="images/img.jpg" alt="" /><span id="desc"></span>
</div>

<script type="text/javascript">
    meToo.Images = ['images/img.jpg','images/img2.jpg','images/img3.jpg','images/img4.jpg','images/img5.jpg'];
    meToo.Titles = ['Pic1','pic2','Pic3','Pic4','Pic5'];
    meToo.Play('img');
</script>  

Javascript Object

var meToo = {
     Images: [],
     Titles: [],
     counter: 0,
     Play: function(ElemID){
         var element = document.getElementById(ElemID);
         var ImgLen = this.Images.length;

         if(this.counter < ImgLen){
             this.counter++;
             element.src = this.Images[this.counter];
             element.nextSibling.innerHTML = this.Titles[this.counter];
         }else{
             this.counter = 0;
         }
         setTimeout(this.Play, 1000);
    }   
};

See the Example

  • 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-06T18:10:52+00:00Added an answer on June 6, 2026 at 6:10 pm

    See this question. Otherwise setTimeout sets this to the window object. Also, the counter should be incremented after setting the images or you will be reading outside the array bounds.

    Finally, when resetting the counter to 0, there will be an additional one-second delay before the loop restarts, because the image is not being reset in that else block. You may wish to rewrite that part of the logic.

    Updated Fiddle

        if(this.counter < ImgLen){
            element.src = this.Images[this.counter];
            element.nextSibling.innerHTML = this.Titles[this.counter];
            this.counter++;
        }else{
            this.counter = 0;
        }
        var _this = this;
        setTimeout(function() { _this.Play('img') }, 1000);
    

    This is what I would write to keep the loop going at one-second intervals:

    Play: function(ElemID) {
        var element = document.getElementById(ElemID);
        var ImgLen = this.Images.length;
    
        if (this.counter == ImgLen) {
            this.counter = 0;
        }
        element.src = this.Images[this.counter];
        element.nextSibling.innerHTML = this.Titles[this.counter];
        this.counter++;
    
        var _this = this;
        setTimeout(function() {
            _this.Play('img')
        }, 1000);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just beginning to have a look at Objective-C and Cocoa with a view
Since beginning to use VB.NET some years ago I have become slowly familiar with
I'm beginning a large scale javascript application with Marionette. A Marionette application has a
I am beginning WPF, and I am having a bit of a hard time
Just beginning my journey in ASP.Net MVC and I have a query about something
I'm beginning to learn javascript and I wrote an infinite loop <script> while(1==true){ document.write(hello
I'm a beginning Vim user. I hate pressing the Esc key, which is a
I was beginning to design a new game for the iPad and I came
When beginning a new web project, i'm always a bit worried about removing pieces
I am beginning a new Java web application using Netbeans, and I would like

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.