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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:43:45+00:00 2026-06-04T09:43:45+00:00

I am trying to create a simple image slideshow type thing with the Javascript

  • 0

I am trying to create a simple image slideshow type thing with the Javascript code below, but what it is doing is displaying the first image in the webpage with everything else, then after 5 seconds clearing the page and displaying the same image, then again every 5 seconds except it doesn’t clear the page anymore.

The JavaScript:

var waiPics=new Array();
waiPics[0]='images/path.jpg';
waiPics[1]='images/gorse.jpg';
waiPics[2]='images/stream.jpg';
waiPics[3]='images/pines.jpg';
waiPics[4]='images/stump.jpg';

var time;

function timeUp() {
    delete document.write();
    nextPic();
}



function nextPic() {
    var picNum=0;
if (picNum = waiPics.length) {
    picNum=0;
}
else {
    picNum++;
} 
    document.write('<img src="'+waiPics[picNum]+'" title="Waipahihi" alt="Waipahihi">');
    time=setTimeout("timeUp()",5000);
}

The HTML:

<script type="text/javascript">
<!-- Begin
nextPic();
//  End -->
</script>

Im not very experienced with Javascript, so thanks in advance for the help.

  • 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-04T09:43:46+00:00Added an answer on June 4, 2026 at 9:43 am

    picNum will always be zero because it is declared inside a function and will set to zero every time the function is called. Even if you fix this, your condition is wrong:

    if (picNum = waiPics.length) {
    

    The conditional should be:

    if (picNum === waiPics.length) {
    

    The single = sign assigns the length to picNum, then converts to a boolean. The array length is nonzero, so it becomes true value. It then resets to zero every time.

    Consider using JSLint to check your code for errors and to suggest improvements. It flagged the issue:

    "Expected a conditional expression and instead saw an assignment."
    if (picNum = waiPics.length) {
    

    In fact, after using JSLint on your code and examining its suggestions, I would use something more like this:

    // New array creation syntax
    var waiPics = ['images/path.jpg', 'images/gorse.jpg', 'images/stream.jpg', 'images/pines.jpg', 'images/stump.jpg'];
    
    var picNum = 0;  // Declare outside inner function so its value is preserved
    var myDiv = document.getElementById("ssdiv");  // Get a div element to insert picture into
    
    function nextPic() {
        if (picNum === waiPics.length) {    // Proper comparison
            picNum = 0;
        } else {
            picNum += 1;
        }
    
        // Set picture into div element without evil document.write
        myDiv.innerHTML = '<img src="' + waiPics[picNum] + '" title="Waipahihi" alt="Waipahihi">';
    
        // No longer need timeUp; also don't use eval syntax
        setTimeout(nextPic, 5000);
    }
    

    Assigning innerHTML avoids various problems with document.write and also does not require your page to refresh to change slideshow images. Also note other comments.

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

Sidebar

Related Questions

I am trying to create a simple image slideshow that fades in and out
Im trying to create a simple pan and zoom app using silverlight 4, but
Im trying to create a simple input box with form validation, but im not
I'm trying to create a simple search page, but I'm not 100% sure how
Im trying to create a simple image resize feature, can you tell me where
I'm trying to create a simple function, but at runtime firebug says the function
I am trying to create a simple menu using li elements, but it only
I'm trying to create a fairly simple piece of JavaScript that displays a random
I'm trying to create a simple image gallery, showing 16 images per page. I'm
I am trying to create a tabBarItem image in Inkscape. I drew a simple

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.