What if choice1 is rock? syntax error missing } after function body?


#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 === "scissors") {
                    if(choice2 === "paper") {
                        return "scissors win";
                    }
                    else  {return "rock wins";}
                }

`


#2

this curly bracket is a loner and you need to remove it..
You are missing a curly bracket at the end as your else if statement is not closed


#3

i removed my loner { and got this msg 'SyntaxError: expected expression, got '}' . Does that mean i'm still missing a } or i have an extra


#4

could you paste in your full code


#5

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 === "scissors") {
                    if(choice2 === "paper") {
                        return "scissors win";
                    }
                    else  {return "rock wins";}
                }

#6

You are missing a closing bracket have a look at the comments below :arrow_down:

 else if (choice1 === "scissors") { //opening elseif
                    if(choice2 === "paper") { //opening_if
                        return "scissors win";
                    } //closing_if
                    else  {return "rock wins";} //opening and closing_else
                } //closing elseif
// where's closing } for your function ?

#7

3 posts were split to a new topic: Computer Choice: Part 1