Hello my code won't work. Rock Paper Scissors


#1

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";
}

#2

The idea is that if you look at one player you have 4 options tie,rock,paper and scissors.

so in pseudo code it would be

if(tie){...}
else if(c1 == "rock"){...}
else if(c1 == "paper"){...}
else if(c1 == "scissors"){...}

Now your done with choice1 what you now need to do is to cover choice2 in the part that is shown like this {...}.
As the tie case is already dealt with you need to consider the other two options which leads you to an if else statement or if you want to be specific an if else if one. An example for this can be found in the hint of 6/9 unless you already figured this out by now.

So if you have a look at your code you can see that these {}

else if(choice1 === "rock") {
}

should rather wrap the following if else and that for the next case you missed the closing } for the else if and the closing } for the function.


#3

Thank you. I knew it would be the brackets. I'm totally rubbish at them. I'll got have a go at putting some more in.


#4

So after my changes it now looks like this, and the computer still doesn't like it. I've got all my brackets in the places it says to have them, but it still hates my syntax.

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";
    }

}

#5

else if(choice1 === "paper")
}

you are using the wrong bracket "}"
use this {


#6

Also add a } at the very end to close the function as well.