Loading updated page, do i need backend for it?

so i build this little game of words that updates to a new puzzle at a certain time every day, it worked, as I play the new puzzle(given the fact I deployed it on netlify, so this feedback is from an online version of the game),
but if I open the link to this website in a new tab(like if another user wants to play today’s puzzle), it does not give me the updated puzzle, instead, it gives me the old puzzle.
now I know I still don’t know about backend and I sense that this needs a database to store and retrieve the new puzzle or something.
so I want to know your advice on how to deal with this? is it possible to do this on just front-end? or do I need backend to make this complete?
thank you.

It depends on how you coded for updating a new puzzle. Can you paste a link of your code only then I can tell.

We can’t say anything without knowing how this works. We need to see code and a live example.

How are you getting the puzzle and how and when is a new puzzle generated?

So here is an example:
I set the variable for the word that should be guessed as below:

Let word1 = "words";

This is the initial value of the word puzzle that should be guessed by keep passing letters to a row of divs, but this just an initial value for creating the variable(to avoid undefined values being shown on the row).
Then i set an setInterval function that execute every second which have an if statment that if a certain local time is met, the variable is reasigned a word randomly from an array of english words:

let array =['brain','great','arson'];
let date = new Date();
setInterval(()=>{
    If(date.getHours() == 12){
            word1 = array[Math.floor(Math.random()*array.length];/*this basicly randomly give an index to the array, to get a random word from it.*/
    }
},1000);

And then there is more code on setting the random word on the row but hidden so when the user try a word and hit enter the right letters go green and wrong letters disappear and so on…
So after i put it online and waited till 12 pm, it worked, puzzle got updated, i played it, if puzzle is guessed right, a dialog shows up and gives a countdown till next puzzle…
The issue is if i open the website again, as a new player, i need the new word to be ready for me to play, instead i find that the first value of word1 which was equal to “words”, is the one at play.
So how to store every new word puzzle and make it available for every new player untill the next 12pm hits, and then change it so they will play the new word and it keeps going on like that(the list of words is long enough for a year or so)?
My feelings tell me it’s a database thing, but i didn’t take any backend yet so i don’t know, im currently trying the browser localStorage to store the daily word fir each player…

If you want the puzzle to be the same for all players on the same day then you should use the date and not an interval as the starting point. A day of the month can be used as an index for example.

If you need to keep some player information you can save that to localStorage (like progress, puzzles played, the number of guesses, etc.). But it isn’t truly persistent as it can be cleared. For truly persistent player information it has to be saved to a DB.

Also, just to point it out, a new player does not know which puzzle is new or old.

i think i have finished building this game, problem solved today, the game doesn’t generate a new puzzle on every refresh, instead the dialog i created to inform user to wait till next day is working very well. it all worked out, thanx to you guys.
if this webgame generates any ad revenue, i’m donating to fcc =).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.