I dont see an error


#1
 else if ( choice1 === "paper"){
    if (choice2 === "rock"){
        return "rock wins";
    }
}
else {
    return  "scissors  wins";
}

};
SyntaxError: Unexpected token else


#2

you have else if to check for choice 1:

else if ( choice1 === "paper"){

}

inside else if nest an if and else to check for choice2:

else if ( choice1 === "paper"){
    if(){

   } else {

   }
}

see how i nested else inside else if? And how this differs from your code?

If you need more help, post an updated version of your full code


#3

else if ( choice1 === "paper"){
if (choice2 === "rock"){
return "paper wins";
}
else {
return "scissors wins";
}
}
whats the problem with this one


#4

please include full code like i asked


#5

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

   
};

#6

the mistake i just highlighted for choice1 is paper, you make the same mistake earlier for choice1 is rock.


#7

so for the first else if i should change it to paper i still confused about where the error lies


#8

can i see an updated version of your code?


#9

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 {
return "paper wins";
}

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

};


#10

you make the exact same mistake, again?

again you placed your else for choice2 outside your choice1 is scissors


#11

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