-1

Old code: restart(" Game Over. Try again!");

    playerLives = 10;
    playerLivesCount.textContent = playerLives;
    setTimeout(() => window.alert(text), 100);
};

This works great in a popup window. I need a pretty popup so i decided to use sweetalert2.

New code: Swal.fire(" Game Over. Try again!");

But now "OK" button does not run the function Restart.

How to use restart with Swal.fire ? enter image description here

Denis
  • 159
  • 2
  • 4
  • 17

1 Answers1

1

Assuming that restart is a function that restarts the game, you could write the alert as follows:

Swal.fire(" Game Over. Try again!").then(() => {
  restart();
});

You would also want to remove the logic from the restart function that previously fired an alert.

micahlt
  • 377
  • 2
  • 11