I'm not all that experienced of a code and I'm stuck on a the while loop towards the bottom of the block of code below
My code is supposed to get the date, check if today is a day when we don't ship (saturdays, sundays, holidays) and, if it is, add 1 day until until it finds the next day that we are on open on and write it to the document.
var target = new Date();
var targetDay = target.getDay();
var targetDate = target.getDate();
var targetMonth = target.getMonth();
function checkIfClosedOnTarget(targetDay,targetDate,targetMonth){
var areOpenOnTarget = true;
if(
targetDay == 0 ||
targetDay == 6 ||
(targetDate == 1 && targetMonth == 0) || // New Year's Day
(targetMonth == 4 && targetDate >= 25 && targetDay == 1) || // Memorial Day
(targetMonth == 6 && targetDate == 4) || //Independence Day
(targetMonth == 8 && targetDate <= 7 && targetDay == 1)|| //Labor Day
(targetMonth == 10 && targetDate <= 28 && targetDate >= 22 && targetDay == 4)|| // Thanksgiving Day
(targetMonth == 11 && targetDate == 25)
){
areOpenOnTarget = false;
}
if(areOpenOnTarget){
return true;
}else{
return false;
}
};
function addDaysUntilNextOpenDay() {
while(checkIfClosedOnTarget(targetDay,targetDate,targetMonth) == false){
target.setDate(target.getDate() + 1);
}
};
addDaysUntilNextOpenDay();
document.write("<p>Next shipment will ship out on " + target.getMonth() + " " + target.getDate + ", " + target.getYear) + " at 4:00pm Pacific Standard Time ";
checkIfClosedOnTargetwhich would imply that it returnstrueif closed, but it returns true if open. And it's wordy. Try renaming it toisOpenorisOpenOn. Then you really just need to return false in your big if statement, and true outside of it. There is no need for theareOpenOnTargetvariable at all.