JavaScript - How to Wait / SetTimeOut / Sleep / Delay

后端 未结 2 1200
谎友^
谎友^ 2021-02-04 13:56

This again is my Rock Paper Scissors game.

At present state the user can\'t see what\'s happening because after being prompted for input(Rock, Paper or Scissors) they ar

2条回答
  •  不要未来只要你来
    2021-02-04 14:22

    This took me a long time to figure out but here was the solution.

    Create this function

    function sleep(miliseconds) {
        var currentTime = new Date().getTime();
        while (currentTime + miliseconds >= new Date().getTime()) {
        }
    }
    

    Add this into my code where I wanted the delay

    sleep(3000)
    

提交回复
热议问题