Lesson 6


#1

can anyone tell me what is wrong with this code?

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

#2
if choice2 ==="scissors"){
  ^

Missing an opening parenthesis right there good buddy!


#3

I'm sure your trying to achieve something like this.

var compare = function(choice1,choice2){
if (choice1 === choice2){
return"The result is a tie!"
}
else if(choice1 === "rock" && choice2 ==="scissors"){
return "rock wins";
}
else {
return "paper wins";
}
}
compare("rock","scissors");

if your are not familiar with the " &&" used above, you can try adding other "else if " statements to make your code work. Also, you missed an opening bracket.e.g.

var compare = function(choice1,choice2){
if(choice1 === choice2) {
return "The result is a tie";
}
else if (choice1==="scissors") {
if (choice2==="rock") {
return "rock wins";
}}
else {
return "scissors wins";
}
}

compare("scissors","rock");

#4

@unimog he had the correct thought process. Later on he will have to add "choice1 === paper" and "choice1=== rock". And the randomizer for the computer will be deciding what it is that choice2 will be.

var compare = function(choice1,choice2){
if(choice1 === choice2) {
return "The result is a tie";
}
else if (choice1==="scissors") {
if (choice2==="rock") {
return "rock wins";
}} //The else needs to be a part of this last if statement inside the elseif statement.
else {
return "scissors wins";
} /* This else statement currently takes the else when choice1 isn't choice2 and
if the user hasn't chosen "scissors" */
}