0
function showWinner(Winner){
    if (Winner === "user"){
        winner.innerHTML = `You Win!`;
    } else if (Winner === "computer") {
        winner.innerHTML = `You Lose!`
    } else {
        winner.innerHTML = `Drawn`;
    }
    gameTable.style.display = "none";
    mainScreen.style.display = "none";
    showResult.style.display = "flex";
}

In the above code, I want the function to stop for 2 seconds before changing the styles of the dom elements, how can that be done using pure javascript.

ayman tarig
  • 73
  • 1
  • 9

1 Answers1

0

You can simply use setTimeout

setTimeout(showWinner(Winner),2000);

Note time is in milliseconds

Maheer Ali
  • 35,834
  • 5
  • 42
  • 73
  • +1 but the syntax is not quite right, it'd have to be `setTimeout(() => showWinner(Winner), 2000);` resp. `setTimeout(function() { showWinner(Winner) }, 2000);` – qqilihq Jan 26 '19 at 17:54
  • 1
    Also see here for explanation how to pass the Winner variable to the function: https://stackoverflow.com/a/7503942/3177115 – ESP32 Jan 26 '19 at 17:54