dimanche 1 octobre 2017

Stopped working

I worked up this code with dummy images and all the same link. When I put in the real images and links (which also made me increase the number of elements in the arrays), the code stopped shuffling. It runs the shuffle code, but the images aren't going up in random order each time like they were previously. They are just staying in the order they are defined in. I need to get this fixed ASAP. Any ideas?

Javascript Code

    var $sectionOne = $('#sectionOne');
    var $sectionTwo = $('#sectionTwo');
    var $sectionThree = $('#sectionThree');
    var $sectionFour = $('#sectionFour');

    var adOne = new Array();
adOne[0] = '<a target="_blank" href="http://ift.tt/1kH012g"><img src="./resources/adimages/October/blessings.png"/></a>';
adOne[1] = '<a target="_blank" href="http://mummydeals.org/"><img src="./resources/adimages/October/clair.jpg"/></a>';
adOne[2] = '<a target="_blank" href="http://ift.tt/2g2SumM"><img src="./resources/adimages/October/onlinetrade.jpg"/></a>';
adOne[3] = '<a target="_blank" href="http://ift.tt/2hGNYhA"><img src="./resources/adimages/October/villageshop.png"/></a>';
adOne[4] = '<a target="_blank" href="./resources/adimages/October/starlightmusic.png"><img src="./resources/adimages/October/rsz_starlightmusic.png"/></a>';
adOne[5] = '<a target="_blank" href="http://ift.tt/2g0wRU7"><img src="./resources/adimages/250yah.png"/></a>';

var adTwo = new Array();
adTwo[0] = '<a target="_blank" href="http://ift.tt/2hEZYjH"><img src="./resources/adimages/October/honeydew.png"/></a>';
adTwo[1] = '<a target="_blank" href="http://ift.tt/2g2SuTO"><img src="./resources/adimages/October/jennappel.jpg"/></a>';
adTwo[2] = '<a target="_blank" href="http://ift.tt/2g0wRU7"><img src="./resources/adimages/250-125yah.png"/></a>';

var adThree = new Array();
adThree[0] = '<a target="_blank" href="http://ift.tt/2hG62Zl"><img src="./resources/adimages/October/acoustic.jpg"/></a>';
adThree[1] = '<a target="_blank" href="http://ift.tt/2g2SvqQ"><img src="./resources/adimages/125_kingcover.jpg"/></a>';
adThree[2] = '<a target="_blank" href="http://ift.tt/2g0wRU7"><img src="./resources/adimages/125yah.png"/></a>';

var adFour = new Array();
adFour[0] = '<a target="_blank" href="http://ift.tt/2cX3YID">The Usual Mayhem</a>';
adFour[1] = '<a target="_blank" href="http://ift.tt/2g2SvXS">Blooming With Joy | Tea Blends & Gifts</a>';
adFour[2] = '<a target="_blank" href="http://ift.tt/2hECo6t">Buy or sell AVON online</a>';
adFour[3] = '<a target="_blank" href="http://ift.tt/2g2B6OW">The Boondocks Wentworth</a>';
adFour[4] = '<a target="_blank" href="http://ift.tt/2hGJdVa">Thrive Well with Essential Oils!</a>';
adFour[5] = '<a target="_blank" href="http://ift.tt/2g2PczX">Perfectly Posh... Because you deserve it!</a>';
adFour[6] = '<a target="_blank" href="http://ift.tt/2hFUHZa">Whole Family Plant Based Wellness</a>';
adFour[7] = '<a target="_blank" href="http://ift.tt/2g2SwuU">Linen World and More</a>';
adFour[8] = '<a target="_blank" href="http://ift.tt/2hGA4fj">All your legging needs- sizes 2T-26W</a>';
adFour[9] = '<a target="_blank" href="http://ift.tt/2g0wRU7">Link to your blog or business. $10</a>';

$(document).ready(function() {

//Shuffle one
adOne.shuffle = function() {
    var input = this;

    for (var i = adOne.length-1; i >=0; i--) {
        var randomIndex = Math.floor(Math.random()*(i+1));
        var itemAtIndex = adOne[randomIndex][0];
            var itemAtSecond = adOne[randomIndex][1];

        input[randomIndex][0] = input[i][0];
            input[randomIndex][1] = input[i][1];
        input[i][0] = itemAtIndex;
            input[i][1] = itemAtSecond;
    }
    return input;
}
//end of shuffleOne function

//Shuffle two
  adTwo.shuffle = function() {
      var input = this;

      for (var i = adTwo.length-1; i >=0; i--) {
          var randomIndex = Math.floor(Math.random()*(i+1));
          var itemAtIndex = adTwo[randomIndex][0];
            var itemAtSecond = adTwo[randomIndex][1];

          input[randomIndex][0] = input[i][0];
            input[randomIndex][1] = input[i][1];
          input[i][0] = itemAtIndex;
            input[i][1] = itemAtSecond;
      }
      return input;
  }
  //end of shuffleTwo function

  //Shuffle three
    adThree.shuffle = function() {
        var input = this;

        for (var i = adThree.length-1; i >=0; i--) {
            var randomIndex = Math.floor(Math.random()*(i+1));
            var itemAtIndex = adThree[randomIndex][0];
                var itemAtSecond = adThree[randomIndex][1];

            input[randomIndex][0] = input[i][0];
                input[randomIndex][1] = input[i][1];
            input[i][0] = itemAtIndex;
                input[i][1] = itemAtSecond;
        }
        return input;
    }
    //end of shuffleThree function

    //Shuffle four
      adFour.shuffle = function() {
          var input = this;

          for (var i = adFour.length-1; i >=0; i--) {
              var randomIndex = Math.floor(Math.random()*(i+1));
              var itemAtIndex = adFour[randomIndex][0];
                var itemAtSecond = adFour[randomIndex][1];

              input[randomIndex][0] = input[i][0];
                input[randomIndex][1] = input[i][1];
              input[i][0] = itemAtIndex;
                input[i][1] = itemAtSecond;
          }
          return input;
      }
      //end of shuffleFour function
adOne.shuffle();
adTwo.shuffle();
adThree.shuffle();
adFour.shuffle();

for (i=0; i < adOne.length; i++) {
$sectionOne.append('<div class="one"> ' + adOne[i] + '</div>');
};
//end of placeAdsOne function

placeAdsTwo = function(adTwo, $sectionTwo, i) {
$adInSectionTwo = $('<div class="two"> ' + adTwo[i] + '</div>');
$sectionTwo.append($adInSectionTwo);
};
//end of placeAdsTwo function

placeAdsThree = function(adThree, $sectionThree, i) {
$adInSectionThree = $('<div class="three"> ' + adThree[i] + '</div>');
$sectionThree.append($adInSectionThree);
};
//end of placeAdsThree function

placeAdsFour = function(adFour, $sectionFour, i) {
$adInSectionFour = $('<div class="four"> ' + adFour[i] + '</div>');
$sectionFour.append($adInSectionFour);
};
//end of placeAdsFour function


for (i=0; i < adTwo.length; i++) {
 placeAdsTwo(adTwo, $sectionTwo, i);
};


for (i=0; i < adThree.length; i++) {
 placeAdsThree(adThree, $sectionThree, i);
};


for (i=0; i < adFour.length; i++) {
 placeAdsFour(adFour, $sectionFour, i);
};

});
//end of document ready




Aucun commentaire:

Enregistrer un commentaire