7/9 SyntaxError


#1

This is my 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";
    }
}

else if (choice1 === "paper") {
    if (choice2 === "rock") {
        return "paper wins";
    }
    else {
        return "scissors wins";
    }
}

*I'm sure the solution is staring me right in the face but I can't seem to find it haha, please help :)*


#2
else if (choice1 === "rock") {
    if(choice2 === "scissors")
    return "rock wins";
}
else {
    return "paper wins";
    }
}

here you messed up with the {}. You probably need to add a { after if or when that was intended, then you need to delete the } before else. Anyway in the end it should have a similar structure then this case:

else if (choice1 === "paper") {
    if (choice2 === "rock") {
        return "paper wins";
    }
    else {
        return "scissors wins";
    }
}

and last but not least add a } to close the compare function.


#3

something tells me the top part is wrong, but i just saw your post and my if/else statement was already correctly formed like your above statement. It keeps saying syntax error and I can't figure out how? I also read your post from other forum post and I thought I understood, but obviously not.

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

#4

you seem to lack a closing } for your function.


#5

i thought that's was the final } closes it out I'm so confused :sob:
the error that comes up is unexpected end of input

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

#6

i got it the "else { " was the problem


#7

Ah yes, I was silly to miss that, thank you very much, it's now solved :grinning: