Rock paper scissors, nesting...Unexpected 'else' Error


#1

Hey All - Struggling with what a syntax 'else' error. I though the syntax i had constructed for the nested else if statement was correct but for some reason I'm receiving a syntax error for the way i'm using 'else'.


Is the bracketing or structure incorrect?


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

I can tell you right now you're missing at least one bracket. I'll leave it to you to find out where. Oh the many joys of debugging :slight_smile:

If you still can't find it, or if it doesn't work, just let me know and I'll provide more assistance.


#3

Thanks for quick reply.

Luckily, was able to realize I required an additional '}' before the last else statement.


#4

Glad I could help! I don't mean to pester, but I'd be ever so grateful if you were to mark my answer as the solution.


#5

No worries at all. Just took care of it.

Happy Friday!


#6

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