vendredi 17 novembre 2017

Javascript if else timer on specific days

I am using this code

Here is a codePen to see it. http://ift.tt/2zNxMC5 But the console doesn't seem to log any of my if else statements, except for the first log. What is wrong in the code, where it is not firing each of my conditions ?

function showDateContent() {
  var d = new Date();
  console.log(d.getDate(), d.getMonth());
  if (d.getDate() >= 4 && d.getDate() <= 17 && d.getMonth() + 1 == 12) {
    console.log("date is between 12/4 and 12/17");
  } else if (d.getDate() >= 18 && d.getDate() <= 30 && d.getMonth() + 1 == 12) {
    console.log("date is between 12/18 and 12/30");
  } else if (d.getDate() >= 31 && d.getMonth() + 1 == 12 || d.getDate() >= 1 && d.getMonth() + 1 == 1) {
    console.log("date is after 12/31/2017 or we are in the New Year of 2018");
  }
}
showDateContent();

Aucun commentaire:

Enregistrer un commentaire