title: JavaScript If Count
body: <p>I think I must be missing something very obvious. Using this code I want to count up and trigger a background change on a timer; however it doesn't pass the variable, each time the timer calls the function it is passing a undefined variable. </p>
  
  <p><strong>Worth noting:</strong></p>
  
  <ul>
  <li>Looked at the consol - no errors</li>
  <li>I know Jquery would arguably be better but the site can't have jquery due to some nasty legacy issues (thats a whole other question)</li>
  </ul>
  
  <p><strong>The Code</strong></p>
  
  <pre><code>&lt;script&gt;
  /* Get the body element */
  var body = document.getElementsByTagName('body')[0];
  /* Call the function */
  changebackground();
  /* Set the starting count */
  var changecount = 1;
  /* Change function */
  function changebackground(changecount) {
      if(changecount=1){
          body.style.backgroundImage = 'url(/templates/images/background_1.jpg)';
          changecount = 2;
      }
      else if (changecount=2) {
          body.style.backgroundImage = 'url(/templates/images/background_2.jpg)';
          changecount = 3;
      }   
      else {
          body.style.backgroundImage = 'url(/templates/images/background_3.jpg)'; 
          changecount = 1;
      }
  setInterval(function(changecount){changebackground();},3000);
  }
  &lt;/script&gt;
  </code></pre>