Help > having trouble with the rock, paper, scissors game


#1



SyntaxError: Unexpected token else


var userChoice = prompt("Do you choose rock, paper, scissors, lizard, or Spock?");
var computerChoice = Math.floor(Math.random() * 5);
if (computerChoice === 0) {
	computerChoice = "rock";
} else if(computerChoice === 1) {
	computerChoice = "paper";
} else if(computerChoice === 2) {
    computerChoice = "scissors";
} else if(computerChoice === 3) {
    computerChoice = "lizard";
}  else {
	computerChoice = "Spock";
} 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 if (choice2 === "lizard") {
                   return "rock wins";
               } else if (choice2 === "Spock") {
                   return "Spock wins";
               } else {
                   return "paper wins";
                   }
            }
          else if (choice1 ==="paper") {
              if (choice2 === "rock") {
                  return "paper wins";
                  } else if (choice2 === "lizard") {
                      return "lizard wins";
                  } else if (choice2 === "Spock") {
                      return "paper wins";
                  } else {
                      return "scissors wins";
                      }
              }
            else if (choice1 === "scissors") {
                if (choice2 === "rock") {
                    return "rock wins";
                    } else if (choice2 === "lizard") {
                        return "scissors wins";
                    } else if (choice2 === "Spock") {
                        return "Spock wins"};    
                    } else {
                        return "scissors wins";
                        }
                }  
            else if (choice1 === "lizard") {
                if (choice2 === "rock") {
                    return "rock wins";
                    } else if (choice2 ==== "paper") {
                        return "lizard wins";
                    } else if (choice2 === "scissors") {
                        return "scissors wins";
                    } else {
                        return "Spock wins";
                        }
                } 
            else if (choice1 === "Spock") {
                if (choice2 === "rock") {
                    return "Spock wins";
                    } else if (choice2 === "paper") {
                        return "paper wins";
                    } else if (choice2 === "scissors") {
                        return "Spock wins";
                    } else {
                        return "lizard wins";
                        }
                }    
    };
    
 compare(userChoice,computerChoice);


#2

Just a few syntax errors


#3

Thank you!!! I thought I was going crazy staring at it!


#4

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