Need help on forcing player to choose a viable option


#1


`
//The problem is the third line. I want it to basically say if userChoice is not rock paper or scissors "pick a valid answer" but I am not sure how to separate rock paper and scissors so i tried ":"and "," and "+"but none work what should i do? Also how can i make it so that if the user does not put in a valid answer it will give them the pick a valid answer message and then take them back to line two where they must pick a answer?

var userName= prompt("what do you want your username to be");
var userChoice = prompt("Do you choose rock, paper or scissors?");
if(userChoice!== "rock":"paper":"scissor"){comfirm (pick a valid answer);};
console.log (userName+" chooses "+userChoice);
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer chose " + computerChoice);
var compare= function (choice1,choice2){
if (choice1===choice2)
{return "The result is a tie!";}
else if (choice1==="rock") if (choice2==="scissors"){return "rock wins";}
else {return "paper wins";}
else if (choice1==="paper") if (choice2==="rock"){return "paper wins";}
else {return "scissors wins"}
};

compare (userChoice,computerChoice);


#2

@romanello,
What you want

userChoice!== "rock" &&userChoice !== "paper" && userChoice !== "scissor"

Have a look at the logical operators
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators