0

I try to reset the game when the same form to start the game is submited. When the game start, the button change to "Stop Game", but when I try to stop the game by clicking on him (I refresh the page with location.reload() : the same thing I do to finish the game and it work), so when I try to stop the game, nothing is happening, and the console.log() is correctly executed, and I'm sure the reload() is done correctly but the game doesn't reset. Any idea ?

startForm.addEventListener('submit', function () {
    if (!Game.onGame) {
        Game.onGame = true
        initFilters(Game)
        Grid.placeRandomImages(Game)
        GamePlay.run(Game)
     } else {
        console.log('reload')
        location.reload()
     }
})

---------- Solution ----------

I need to event.preventDefault() the submission of the form

Meds
  • 111
  • 1
  • 7
  • 1
    Try `e.preventDefault()` at the top of the function and make sure to accept the event parameter with `function (e)` instead of `function ()`. – ggorlen Jul 23 '21 at 06:07
  • 1
    event.preventDefault() is working ! Thank's a lot ! – Meds Jul 23 '21 at 06:08

0 Answers0