Need help with getting a countdown to work correctly

Need help with getting a countdown to work correctly
0.0 0

#1

The string of code is below, currently says that the error is with trying to define the year.

var before = “graduation!” ;
var current = “Last day to use the worthless Knowledge”; // Message to display on future (graduation) date
var montharray = new Array(“January”,“February”,“March”,“April”,“May”,“June”,“July”,“August”,“September”,“October”,“November”,“December”);

function countdown(yr, m, d){
var today = new Date();
var today = today.getDay();
var todayYr = today.getYear();

if(todayYr < 1000){
    todayYr += 1900;
    var todaym = today.getMonth();
    var todayDay = today.getDate();
    var todaystring = montharray[todaym] + " " + todayDay + "," + todayYr;
    var futurestring = montharray[m - 1] + " " + d + "," + yr;
    var difference = (Math.round((Date.parse(futurestring) - Date.parse(todaystring)) / (24 * 60 * 60 * 1000)) * 1); // Future (graduation) Date - Today's Date


  if(difference === 0){
      document.write(current);
  }
  else if (difference > 0){
      document.write("Only " + difference + "days until" + before);
  }
}

}

countdown(2018, 4, 25); // Comparison


#2

Just glancing at the code, getYear is deprecated, you shouldn’t use it, and the should be a warning in the console to that effect. It returns two digits (so 18 for date now), that’s always going to be < 1000, and so you’re always going to be adding 1900 to the number.


#3

I see, so instead of getYear what should I use?


#4

You use getFullYear: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear