What if choice1 is paper?


#1

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

;}

I cannot find the error.


#2

Hi this part you should remove the ; at teh closing }

else if (choice1 === "rock") 
{
    if (choice2 === "scissors") 
    {    return "rock wins";}
    
    else 
    {    return "paper wins";}
}; <-- #this one

then thsi line

if (choice2 = "rock")

you should change the = with ===

And

this part you should also remove the ;

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

#3

The program tells me there is an unexpected token else


#4

I'm getting the same error. I'm thinking it's where we're putting the 2nd "else if" statement when choice 1 is paper. You figure it out yet?


#5

HI if you need help you should create a new topic with your code..


#6

I figured it out, so before I start a new thread, all you have to do is delete the curly brackets in between the else if and if. Both should only be in parentheses. Then, after the if one, that's when the curly brackets come in.

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

else {return "scissors wins}

You and I were both putting an additional curly bracket between the else if and if. Took me a long time to figure it out but I got it.


#7

still confused: look this is what i have:
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";}

#8

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