Change Banner Every week

0

I made a code js so that every week the specific advertising banner is changed, in case every Sunday one banner is exchanged for the other. I started doing Javascript , but within the r == 0 compare function document.byelementbyid with style.display was not working. They are working fine, I have done some tests but if it can be simplified it would be great, I'm not sure how to create the weeks.

$(document).ready(function() {
  var d = new Date();
  var weekday = new Array(7);
  weekday[0] = 'Domingo';
  weekday[1] = 'Segunda';
  weekday[2] = 'Terça';
  weekday[3] = 'Quarta';
  weekday[4] = 'Quinta';
  weekday[5] = 'Sexta';
  weekday[6] = 'Sabado';
  var n = weekday[d.getDay()];

  function virada() {
    var i = 0;
    var r = i % 2;
    if (n == weekday[0]) {
      i++;
    }

    if (r == 0) {
      $('#bn1').show();
    } else {
      $('#bn2').show();
    }
  }
  virada();
});
#bn1,
#bn2 {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><body><divid="content" class="content">
    <div class="banner">
      <a href="#" id="bn1"><img src="https://www.revistaapolice.com.br/wp-content/uploads/2018/04/banner_apolice_728x110px.jpg"alt=""></a>
      <a href="#" id="bn2"><img src="https://www.revistaapolice.com.br/wp-content/uploads/2018/04/banner_saude_apolice_728x110px.jpg"alt=""></a>
    </div>
  </div>
</body>
    
asked by anonymous 26.04.2018 / 18:22

0 answers