Ex 7 what if choice 1 is paper syntax error


#1

I have entered this code for Ex7 what if choice 1 is paper and it just keeps giving me a syntax error? I cannot see where the error is and so cannot move forward?

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

You had a few places where you were adding ; when you didn't have to (like after curly brackets). If you notice in the middle after returning paper wins you have a ;. That breaks the if/else statement. Also, you don't have curly brackets after your function enclosing the whole code in it. Here's the same code but with the changes:

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

	}; // here we add a semicolon because we are 
          //assigning the function to the compare var

#3

Thanks for your review and help. However, I have made the alterations as below and it still returns a syntax error? any ideas what else is wrong I cant see it??

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

};


#4

you missed the closing } for the first else if as well.