Need help! Everything works until the end Step 8


#1

I managed to get to the end I'm stuck on 8. What if choice 1 is scissors.


I get this error: SyntaxError: Unexpected token {

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

#2

First off, you don't need { } around any return statements. Second, you have an extra { with having 6 { and 5 }. Third, you are missing an entire else if statement about if scissors is choice 1 and paper is choice 2. Fourth, your organization of this code is really odd and I think just to make it easier for you to read and work with you might try a set up like this:

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

All these returns and else statements running in a long single line could cause problems later on.


#3

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