SyntaxError: Unexpected token else, 7/9


#1


Build "Rock, Paper, Scissors", What if choice1 is paper?

For some reason, my code keeps saying that there is an unexpected token, "else". I've looked at all of the other posts, and still am struggling. If someone could shed some light on this, that would be great.


Replace this line with your 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");
        }
}
}


#2

@alexa.miller_01

I moved around the spacing on your code. Can you find the unexpected else now?

frisby

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

#3

HI this part you have more } than you need so remove one

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

then here you closed the else if statement before

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

#4

Thank you so much! I fixed the spacing on the code, and then I just needed to remove the "}" from my code. And sure enough, it worked!


#5

Thank you, also! I didn't understand at first, and then I removed the extra bracket, or "}", and it worked, and now I'm on the next one! So hopefully, this one doesn't give me problems too. ^_^


#6

That's great, @alexa.miller_01! :slight_smile:

Spacing everything consistently helps a lot, but you can also try pasting your code in labs or repl.it which can sometimes give you more specific error messages :sunglasses:


#7

Thanks for letting me know! I will try next time. I posted because the error didn't give me an idea of what to fix. :slight_smile:


#8

No worries, yes it is just information for next time. :slight_smile: Because finding your own errors can be very satisfying, not because I don't want to help :slight_smile: