title: variable assignment doesn't work javascript
body: <p>In the following code, the console.log from the line 92 and 93 (switchPosition function) doesn't provide the same result. I am, I have to admit, stuck.</p>
  
  <p>Any thoughts, ideas, explanations?</p>
  
  <p>Thanks you for the time taken, </p>
  
  <pre><code>var Carrousel = (function () {
      var self = {},
              config = {
                  item: 3, // item to be displayed
                  scroll: 2 // number of items to be scrolled
              },
      container = null,
              items = null,
              nbItems = null,
              nbSlide = null,
              position = [],
              searchPositionDepending = []
              ;
  
  
  
  
      self.init = function (opts) {
          options = opts || {}
  
          execute();
  
      }
  
      // Private Method
      execute = function () {
          container = document.getElementById('carrousel');
          items = document.getElementsByClassName('flux');
          var containerWidth = container.offsetWidth;
          var containerHeight = items[0].offsetHeight * 1.5;
          container.style.height = '' + containerHeight + '';
          nbItems = document.getElementsByClassName('flux').length;
          nbSlide = nbItems / config.item;
  
          // Initialisation du Carrousel
          for (i = 0; i &lt; nbItems; i++) {
              items[i].style.width = '' + (containerWidth / config.item) + '';
              items[i].style.display = 'none';
              items[i].style.position = 'absolute';
              items[i].style.top = "0";
              items[i].style.left = "0";
              items[i].setAttribute('data-position', '' + (i + 1) + '');
              items[i].setAttribute('data-number', '' + i + '');
          }
  
          searchPosition();
          placement();
  
          document.getElementById('next').onclick = function () {
              next();
              searchPosition();
              switchPosition();
              placement();
              // position();
          }
          document.getElementById('previous').onclick = function () {
              // previous();
              // searchPosition();
              // position();
          }
      }
  
      searchPosition = function () {
          for (i = 0; i &lt; config.item; i++) {
              searchPositionDepending[i] = (function () {         //Appending a function searchPosition per item displayed
                  for (j = 1; j &lt;= config.item; j++) {            //Passing through the first items to get their position 
                      if (items[i].dataset.position === '' + j + '') {
                          position[j] = items[i];
                          return true;
                      } else {
                      }
                  }
                  ;
              })();
          }
      }
  
      switchPosition = function () {
          for (i = 0, j = 0; i &lt; nbItems; i++, j++) {
              if (items[i].dataset.position === '' + j + '') {
                  position[i] = position[i];
              }
          }
          for (i = config.item, j = 1; i &lt; nbItems; i++, j++) { //Replacing in good order, except for the one that are place into the variable position[];
              items[i] = items[j];
          }
  
          for (i = (nbItems - config.item +1), j = 1; i &lt;= nbItems; i++, j++) { //Replacing in good order the one that are place into variable position[];
              items[i] = position[j];
              console.log(i);
              console.log(j);
              console.log(position[j]);
              console.log(items[i]);
          }
  
          for (i = 0; i &lt; nbItems; i++) {
              console.log(items[i]);
          }
          console.log(items[10]);
  
      }
  
      placement = function () {
          for (i = 1; i &lt;= config.item; i++) {
              var rect = items[0].getBoundingClientRect();
              item_width = Math.floor(rect.width);
              item_height = Math.floor(rect.height);
  
              var x = item_width * (i - 1) * 1.1;
  
              items[i].style.display = 'block';
              items[i].style.transform = "translate3D(" + x + "px, 0px, 0px)";
          }
      }
  
      next = function () {
  
          for (i = config.item, j = 1; i &lt; nbItems; i++, j++) { //Updating all dataset position, except for the items that are displayed. 
              items[i].dataset.position = j;
          }
  
          for (i = 1, j = 2; i &lt;= config.item; i++, j--) {
              position[i].dataset.position = nbItems - j;
              position[i].style.display = "none";
          }
  
      }
  
  
      return self;
  
  })();
  </code></pre>