What if choice1 is scissors?


#1

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
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("paper wins")}
    else if(choice1 === "paper"){
           if(choice2 === "rock"){
               return "paper wins"}
               else("scissors wins")}
    else(choice1 === "scissors wins"){
           if(choice2 === "paper wins"){
               return "scissors wins"}
               else("rock wins")}
      };

please help, it is saying SyntaxError: Unexpected token {, but i cannot find what is wrong. Thanks


#2

Alright, the problem is that you're closing your else statements before you're opening them, so let's put your opening brackets on the same line, and closing brackets on their own line.

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

Just go through your opening and closing statements and make sure they add up in the right area, and you should be good to go!


#3

@lolman ok thanks for that, i will do that from now on


#4

Question, should the return lines have semicolons at the end?


#5

Yes, general rule of thumb is any line that doesn't end in parenthesis " ( ) " or brackets " { } " should have a semi-colon.