Rock Paper Scissor Game Additions


#1

I'm not sure if I am doing this correctly but I am trying to extend the
function to handle if the user inputs something other than rock, paper,
scissors. I'm getting an error with what i have that says scissors is
undefined. Help? Any tips?

var userChoice = prompt("Do you choose rock, paper or scissors?");
if (userChoice != "rock" || "paper" || "scissors"){
prompt("Error! Please choose only rock, paper or scissors");
}

else {
userChoice === "rock" || "paper" || "scissors";
}

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 === paper) {
            return("scissors wins");
        }

        else {
            return("rock wins");
        }
    }
}

};

compare(userChoice, computerChoice);


#2

check else statement, where choice1 === scissors. this is comparing to a variable named scissors , not the string 'scissors'.... same thing with paper right underneath it


#4

That worked! I'm not getting an error anymore, thank you! I think my logic is still flawed on the user prompt coz it doesn't seem to be running past that if else statement.


#5

i think your missing an if statements where if choice===rock