# Making the game little bit logical (confused at some point, need help!)

#1

In this code, I tried to make my code ask to user again when the user respond something which is not one of the three. However I am not able to do that yet as you see below. Can u help me to fix my code?? Thanks.

var userChoice = prompt("Do you choose rock, paper or scissors?");
if(userChoice === "rock" "paper" "scissors"){
}
else{
console.log(prompt("You can choose only the three. What do you choose?"));
}

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 "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";
}
}
else if(choice1 === "Scissors"){
if(choice2 === "rock"){
return "rock wins";
}
else{
return "scissors wins";
}
}
};

#2

``if(userChoice === "rock" "paper" "scissors") //wrong``

DO like

``if(userChoice === "rock" ||userChoice === "paper" ||userChoice ==="scissors")``

#3

if(userChoice === "rock" "paper" "scissors")

The above statement will produce error because either the user should select paper or scissor or rock
so you want use || operator.

below syntax is write:

if(userChoice === "rock" ||userChoice === "paper" ||userChoice ==="scissors")

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.