Is there a function to simply reset all JS functions?

Hi there,

I am just wondering if there is a function that would reset all the functions without refreshing the page?

So literally, on the click of a reset button, everything is reloaded and back to initial state.

However I don’t want to reload the page.

This is for my tic tac toe board zipline btw.


for reference, here’s my codepen so far =>

Could you put all the functionality into one larger function that is called on page load (the first time) and can be subsequently fired every time a particular button is pressed?

1 Like

You could try codepen’s run button. Just go to settings, then click on behavior and uncheck “Auto-Updating Preview.” This will add a run button to the page beside save, which effectively just refreshes the preview, and is much faster than refreshing the entire page.

State is something you define as the programmer, so an initializing function is something you’d have to implement. Ideally, you’d already have a function that gets the game into its prime state that you could call for this.

yeah i created an init function – but i wasn’t sure how to recall it on click.

I tried simply referencing it within the click handler like so: init() but that didn’t change the state.

When you say “change the state”, what do you expect to happen?

all the tiles to be wiped and the counter reset basically

There’s nothing in init() that sets the counter, and the code that sets up the tiles just adds divs to the document and adds an event listener. Each time you invoke the function, you’re just adding to the DOM. In order to reset, you’ll need to clear out whatever was there before.