So once i open my container in chrome the dialog box comes up and everything works fine but the problem is that I don’t know how to make the program run constantly. I have a scoreboard for who wins but how do I get the prompt box to come back again or repeat all of the code?
Here is my code:
console.log("hi");
var userChoice = prompt("take your pick(1, 2 or 3): \n 1.Rock \n 2.Paper \n 3.Scissors");
var userScore = 0;
var computerScore = 0;
const userScore_span = document.getElementById("user-score");
const computerScore_span = document.getElementById("computer-score");
const scoreBoard_div = document.querySelector(".score-board");
function win(user, computer) {
userScore = userScore + 1;
userScore_span.innerHTML = userScore;
computerScore_span.innerHTML = computerScore;
console.log(user);
console.log(computer);
console.log(win);
}
function lose(user, computer) {
computerScore = computerScore + 1;
userScore_span.innerHTML = userScore;
computerScore_span.innerHTML = computerScore;
console.log(user);
console.log(computer);
console.log(lose);
} {
if (userChoice == 1) {
userChoice = "Rock";
} else if (userChoice == 2) {
userChoice = "Paper";
} else if (userChoice == 3) {
userChoice = "Scissors";
} else {
alert("Error, press F5");
}
alert("You choose: " + userChoice);
console.log(userChoice);
//computer choice
var computerChoice = Math.random();
if (computerChoice < 0.33) {
computerChoice = "Rock"
} else if (computerChoice < 0.66) {
computerChoice = "Paper";
} else {
computerChoice = "Scissors";
}
alert("Computer choose: " + computerChoice);
console.log(computerChoice);
}
if (userChoice === "Rock" && computerChoice === "Scissors") {
alert("Rock crushes scissors.You Win!");
win(userChoice, computerChoice);
} else if (userChoice === "Rock" && computerChoice === "Paper") {
alert("Paper covers rock. You lose!");
lose(userChoice, computerChoice);
} else if (userChoice === "Paper" && computerChoice === "Rock") {
alert("Paper covers rock. You win!");
win(userChoice, computerChoice);
} else if (userChoice === "Paper" && computerChoice === "Scissors") {
//scissors
alert("Scissors cuts paper. You lose!");
lose(userChoice, computerChoice);
} else if (userChoice === "Scissors" && computerChoice === "Rock") {
alert("Rock crushes scissors. You lose!");
lose(userChoice, computerChoice);
} else if (userChoice === "Scissors" && computerChoice === "Paper") {
alert("Scissors cuts paper. You win!");
win(userChoice, computerChoice);
} else if (userChoice == computerChoice) {
alert("It's a tie!")
}