Unexpected token else



SyntaxError: unexpected token else

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){
//This is an if statement to declare a tie.
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"
    return "paper wins"


Please post a link to the exercise you're on, paste all of the code you have written so far and any error messages that came up when you tried to submit your code.


ok let me edit it i will try to do that i am new to this so ?


ok I am now done with requirements you needed to help me thx


Check your else if statements and if statements for proper syntax. The instructions give you a good idea for what your code should look like for each else if statement.


else if (choice1 code){ //start of else if statement
if (choice2 code){
return "code wins";
} else {
return "code2 wins";
} // end of else if statement

Once you're done with the else if statements, make sure to close the compare function.


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