7. what if choice1 is paper?


#1

Somebody, please let me know where is mistake?
I am receiving note: "problem with syntax" "Unexpected token else"

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";}
        };
};

#2

After formatting your code, the error becomes apparent which is that in:

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

you have a redundant semi-colon on the last line of this code block. Remove it, as well as the redundant semicolon on the second-last line of your whole code.


#3

Thank you , I guess, i had several extra .. Got that fixed!


#4

Hello!

Would you mind sharing your final code when succeeding with step 7?


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


#6

2 posts were split to a new topic: Your compare function does not return 'The result is a tie!'