Why do the images appear only sometimes?

Discussion in 'JavaScript' started by IanT, Jul 18, 2010.

  1. #1
    see example of script in action here:

    http://www.smftutorials.com/testing/template.html

    It will go through 4-5 images, and then no image, then 3-4 more, then no image again... how can I change this script to keep rotating images with no breaks?


    <script type="text/javascript">
    var imgs1 = new Array("http://www.smftutorials.com/images/r-banners/pic1.jpg","http://www.smftutorials.com/images/r-banners/pic2.jpg","http://www.smftutorials.com/images/r-banners/pic3.jpg","http://www.smftutorials.com/images/r-banners/pic4.jpg","http://www.smftutorials.com/images/r-banners/pic5.jpg","http://www.smftutorials.com/images/r-banners/pic6.jpg","http://www.smftutorials.com/images/r-banners/pic7.jpg","http://www.smftutorials.com/images/r-banners/pic8.jpg","http://www.smftutorials.com/images/r-banners/pic9.jpg","http://www.smftutorials.com/images/r-banners/pic-10.jpg","http://www.smftutorials.com/images/r-banners/pic-11.jpg","http://www.smftutorials.com/images/r-banners/pic-12.jpg","http://www.smftutorials.com/images/r-banners/pic-13.jpg");
    var lnks1 = new Array("http://www.soapmakingforum.com","http://www.smftutorials.com/how-to-make-sand-candles-tutorial.html","http://www.smftutorials.com/how-to-make-soap-scroll-tutorial.html","http://www.smftutorials.com/how-to-make-bath-bombs-tutorial.html","http://www.smftutorials.com/how-to-make-melt-and-pour-gemstone-and-rock-soap-tutorial-revisited.html","http://www.smftutorials.com/6-color-swirl-tutorial.html","http://www.smftutorials.com/how-to-line-a-wooden-soap-mold-tutorial.html","http://www.smftutorials.com/soap-packaging-idea-tutorial.html","http://www.smftutorials.com/how-to-make-rebatch-soap-tutorial.html","http://www.smftutorials.com/how-to-make-salt-soap.html","http://www.smftutorials.com/how-to-make-your-own-silicone-soap-mold-liners-tutorial.html","http://www.smftutorials.com/how-to-make-your-own-custom-soap-stamps-tutorial.html","http://www.smftutorials.com/soap-wrapping-ideas-tutorial.html");
    var currentAd1 = -1;
    var imgCt1 = 13;
    function cycle1() {
      if (currentAd1 <= imgCt1)
        currentAd1++;
      else	{
        currentAd1 = 0;
      }
    var banner1 = document.getElementById('adBanner1');
    var link1 = document.getElementById('adLink1');
      banner1.src=imgs1[currentAd1]
      document.getElementById('adLink1').href=lnks1[currentAd1]
      currentAd1++;
    }
      window.setInterval("cycle1()",3000);
    </script>
    <a href=""http://www.soapmakingforum.com"" id="adLink1" target="_top">
    <img src="http://www.smftutorials.com/images/r-banners/pic1.jpg" id="adBanner1" border="0" width="500" height="250"></a>
    
    Code (markup):
     
    IanT, Jul 18, 2010 IP
  2. tdemetri

    tdemetri Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ian- see my message to you - some of those images are not even on the server, so can not show up. other than that - see the PM
     
    tdemetri, Jul 18, 2010 IP
  3. harrierdh

    harrierdh Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You should fix this syntax.

    if (currentAd1 <= imgCt1)
    currentAd1++;
    else {
    currentAd1 = 0;
    }
     
    harrierdh, Jul 20, 2010 IP
  4. IanT

    IanT Well-Known Member

    Messages:
    503
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #4
    What exactly would I fix about that syntax?

    I'm no .js master, still learning 101 phase!
     
    IanT, Jul 20, 2010 IP
  5. harrierdh

    harrierdh Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you're going to use brackets use them consistently. I'm not being a nit picker. Good syntax will keep you from getting stray bugs. Like this:

    
    if (currentAd1 <= imgCt1)  {
        currentAd1++;
    } else {
        currentAd1 = 0;
    } 
    
    Code (markup):
     
    harrierdh, Jul 21, 2010 IP