I would like to show the date in an element on a web page, then once a week on a Saturday it will update to that Saturdays date, if the Saturday of the week hasn't been reached it will simply display the previous Saturdays date until the next Saturday.
I am able to get the date and to extract the day of the week, therefore i can identify when it is a Saturday. I have attempted to include an IF statement that will update the text when Saturday arrives. That seems to be working however I do not know how to keep it displaying the previous Saturdays date until it next updates?
HTML:
<div id="date">
</div>
JS:
var date = new Date(); //Gets current date
var day = date.getDay(); //Isolates what day it is
if (day === 6) {
document.getElementById("date").innerHTML = date;
} else {
//keep the previous saturday somehow?
}
I have a JSFiddle with the code I have been practising with:
https://jsfiddle.net/Lime26/8txryo3k/13/
Seems to be working what I have so far, not sure how to get it to continue displaying the previous Saturdays date.
On a side note: to test this I have been manually changing the day integer between 0 and 6 to determine if it is working which it is.
I am attempting to set the date by entering 6, then I will enter a different number and in theory I would like it to not change (to check it I am watching the seconds and minutes expecting them to remain 'frozen') and then when I enter 6 again I expect it to change to the most current time.