Number Guessing Game doubt

In guess the number game, while the function resetGame() has so much code in it, why not just remove all of that and enter window.reload() so when someone clicks the resetbutton, the page would refresh and this could start a new game with a new random number and reset the count to zero and also when the page refreshes , input field would be enabled and the submitGuessbutton would also work.

Hi @Harshit_Badolla!

Yes, you are right, you could do that. But what happens in the future when you want to implement an updated version that keeps some kind of state (e.g. a record of previous numbers and scores)? Or this games is included in a larger website that has other functionality available, such as other games?

reload() also won’t work if you are calling it from a different domain to the one the main page is loaded in, e.g. if you have the game embedded in another site using an <iframe>.

So in short, I’d say it is not really good practice to do that. but it is an option if you are doing something simplistic like we are in this demo.

I got a better clarity after reading your reply. Thank you !

@Harshit_Badolla You’re welcome.