Rock paper scissors issue javascript
Well i made rock paper scissors in javascript on codeacademy and im trying to make it so that if your input is not "rock" paper or scissor then it will send you an alert and return back to the prompt however im having an issue with it:
the issue itself is if i type anything in, including rock, paper, or scissor it still does the what is inside the "if" statement, so anyone see what is wrong with the check? and also how would i make it go back and ask the prompt question again until the proper input is typed in, i tried a while loop earlier but it didnt work, but i think it didnt work because the check is done incorrectly
Code:
var userChoice = prompt("Do you choose rock, paper or scissors?");
if(userChoice.toLowerCase() !== ("rock" || "paper" || "scissor")) {
alert("Please answer with: rock, paper, or scissor.");
}
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return userChoice = prompt("Do you choose rock, paper or scissors?");
}
if(choice1 === "rock") {
if(choice2 === "scissors") {
return "rock wins";
} else {
return "paper wins";
}
}
if(choice1 === "paper") {
if(choice2 === "rock") {
return "Paper wins";
} else {
return "Scissors wins";
}
}
if(choice1 == "scissors") {
if(choice2 == "paper") {
return "Scissors wins";
} else {
return "Rock wins";
}
}
};
compare(userChoice, computerChoice);