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" ><img src="../img/logo.png" alt="Logo" id="logo"></a>
<script src="js/pride.js"></script>
CodePudding user response:
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) { // ...