I'm trying to switch text between Week 1 and Week 2 every week depending on an array of dates.
Currently it works but only for specified dates, I'm trying to make it keep the text for the whole week until it reaches the next date.
So if the date is Monday 16th April, I want it to display Week 1 for the whole week until it reaches Monday 23rd April.
If not that then would it be possible to change text every Sunday and keep the same text til the following Sunday?
Code
var todaysdate = new Date();
var dd = todaysdate.getDate();
var mm = todaysdate.getMonth()+1; //January is 0!
var yyyy = todaysdate.getFullYear();
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var todaysdate = dd+'/'+mm+'/'+yyyy;
var weekadates =
["17/04/2018", "30/04/2018",//April
"14/05/2018", //May
"04/06/2018", "18/06/2018",//June
"02/07/2018", "16/07/2018",//July
];
var weekbdates =
["23/04/2018", //April
"07/05/2018", "21/05/2018",//May
"11/06/2018", "25/06/2018",//June
"09/07/2018" //July
];
var a = weekadates.indexOf(todaysdate);
var b = weekbdates.indexOf(todaysdate);
if (a > -1)
{
document.getElementById("changeText").innerHTML = "Week 1";
}
else if (b > -1)
{
document.getElementById("changeText").innerHTML = "Week 2";
} else
{
document.getElementById("changeText").innerHTML = "Holidays!";
}
https://jsfiddle.net/naLuny2x/2/
Thanks for your help, much appreciated.