Prompt Delay


#1

Is there a way to have a delay between prompts? I have been considering about setTImeout() but I can't seem to figure it out. I don't want to have a alert between it, just a couple seconds between the prompt.
...
console.log("Most points by 5 wins!");
var scoreList = ["userCounter", "computerCounter"];
scoreList[0] = 0
scoreList[1] = 0
for (i = 0; i < 5; i++) {
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.33333) {
computerChoice = "rock";
} else if(computerChoice <= 0.66666) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if(choice1 === choice2){
return "The result is a tie! " + scoreList[0] + " / " + scoreList[1] ;
}
else if(choice1 === "rock"){
if(choice2 === "scissors"){
scoreList[0] = scoreList[0] + 1
return "Rock wins. " + scoreList[0] + " / " + scoreList[1]
} else {
scoreList[1] = scoreList[1] + 1
return "Paper wins. " + scoreList[0] + " / " + scoreList[1]
}
}
else if(choice1 === "paper"){
if(choice2 === "rock"){
scoreList[0] = scoreList[0] + 1
return "Paper wins." + scoreList[0] + " / " + scoreList[1]
} else {
scoreList[1] = scoreList[1] + 1
return "Scissors wins." + scoreList[0] + " / " + scoreList[1]
}
}
else if(choice1 === "scissors"){
if(choice2 === "paper"){
scoreList[0] = scoreList[0] + 1
return "Scissors wins." + scoreList[0] + " / " + scoreList[1]
} else {
scoreList[1] = scoreList[1] + 1
return "Rock wins." + scoreList[0] + " / " + scoreList[1]
}
}
}
console.log(compare(userChoice, computerChoice));
};
if(scoreList[0] > scoreList[1]) {
console.log("You won!")
} else {
if(scoreList < scoreList[1]) {
console.log("You lost.")
} else {
console.log("You tied.")
}
}
...


#3

I think that you should be able to do it. You will have to wrap your code in the function, but that should not be a problem.

Here is a small example with use of setTimeout -> https://repl.it/ClzH/1.