r/AskProgramming • • 2d ago

Javascript [ Removed by moderator ]

[removed] — view removed post

0 Upvotes

21 comments sorted by

View all comments

Show parent comment

2

u/GrainWeevil 2d ago edited 2d ago

Got it, sounds like local storage is what you're looking for.

Essentially, when you start your application, you'd check if there's a date stored in local storage. If there is, check if a week has passed since that date, and update it if so.

Have a read of this: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

You'll probably need to format the date as a string before trying to save it, but writing to local storage is as easy as:

localStorage.setItem('savedDate', dateString)

And reading it back:

let dateString = localStorage.getItem('savedDate')