Rock Paper Scissors, Part 8 out of 9, another Syntax error for else


#1

syntax is incorrect somehow, but i can't figure it out. Had the same issue on the last nested if statement, and literally copied the exact same bracketing format...


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";
        }
    }
    
    else if (choice1 = "scissors")
        {
        if (choice2 ==="rock")
        {
            return "rock wins";
        }
        }
        else
        {
            return "scissors wins";
        }
    }
    console.log(compare (userChoice, computerChoice));


#2

The problem is with your opening and closing bracket, here's a trick i learnt for making sure your opening brackets correlate with your closing ones. Count every opening bracket and make sure that the number of closing brackets is the same as the number of opening brackets. Additionally make sure they nest the correct data. :slight_smile:


#3

Thanks Bandit, can you be a bit more descriptive?

I believe i'm 1 '{' short, but cannot figure out where to put it.


#4

You are missing one closing bracket at the end of your code, but before your function call,

But also you have one bracket too many in these if and else statements,


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.