Change an image during a month

Issue

I want a certain logo to show up during a month. I tried the following but it never worked. One is a gif and the other is a PNG.

Javascript:

var logo = document.getElementById("logo");

const refreshStatus = () => {
  // Get dates/time/hours
  let today = new Date(); //today date

  //Show available if this matches
  if (today.getMonth == 5) {
    logo.src='../../img/logo2.gif';
  } else {
    logo.src='../../img/logo.png';
  }
}

// run when starting
refreshStatus();

// updates every 8 seconds
setInterval(refreshStatus, 8000);

HTML:

<a href="../index.html" class="index-link"><img src="../img/logo.png" alt="Logo" class="logo" id="logo"></a>
<script src="js/pride.js"></script>

Solution

You need to call getMonth for it is a function (or more specifically a method on Date.prototype). Currently you are comparing a function to a number, which is never true.

if (today.getMonth() == 5) { // ...

Answered By – Jack Bashford

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.