Help! "What if Choice1 is Scissors: Build Rock, Paper, Scissors


#1

This what I have

var userChoice = prompt("Do you choose rock, paper or 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!";
}
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";
        if(choice1 === "scissors") {
            if(choice2 === "rock") 
                return "rock wins"
            }
            else {
                choice2 === "paper"
                return "scissors wins"
            }
    
    console.log(userChoice);
    console.log(computerChoice);
};

I am not sure what I did wrong can anyone explain.? It says syntax error Parser error...what does that mean?


#2

Hey @jessica_davis17! First of all good job on formatting your code!!! Your syntax error was that you were just missing a } (curly bracket)! So put that at the end of your program and you should be fine! If your not then please reply stating your problem! Thankyou!


#3

As @amanuel2 already mentioned you're missing a few curly braces: (This is not a solution I but just your code with some comments)

var userChoice = prompt("Do you choose rock, paper or 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!";
        }
        if (choice1 === choice2) {
            return "The result is a tie!";
        } else if (choice1 === "rock") {
            if (choice2 === "scissors") {
                return "rock wins";
            } else {
                return "paper wins"
            }
        } //correct until here on the next line it gets wrong
        else if (choice1 === "paper") {} //instant close have a look
        // at the case before
        if (choice2 === "rock") {
            return "paper wins";
        } else {
            return "scissors wins";
        // missing } here
            if (choice1 === "scissors") {
                if (choice2 === "rock") // missing { here
                    return "rock wins"
            } else {
                choice2 === "paper"
                return "scissors wins"
            }
            //missing } here
            console.log(userChoice); // should be outside of the function
            console.log(computerChoice); // should be outside of the function
        }; 
        // optional call of the compare function.

#4

This worked for me. I basically copied and pasted the first part and changed up the parts as asked.

var userChoice = prompt("Do you choose rock, paper or 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!"}

//Choice1 Rock
if(choice1===choice2) {return "The result is a tie!"}
else if (choice1==="rock")
if(choice2==="scissors")
{return "rock wins";}
else{return "paper wins";}

//Choice1 Paper
if(choice1===choice2) {return "The result is a tie!"}
else if (choice1==="paper")
if(choice2==="rock")
{return "paper wins";}
else{return "scissors wins";}

//Choice1 Scissors
if(choice1===choice2) {return "The result is a tie!"}
else if (choice1==="scissors")
if(choice2==="paper")
{return "scissors wins";}
else{return "rock wins";} }
compare (userChoice,computerChoice);