What if choice1 is paper? HELP!


#1

I'm on build "rock, paper, scissors", what if choice1 is paper. I keep on getting an unexpected else token and i dont know why. I've on the forums for hours and i cant find the answer I'm looking for. please help!

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#

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") { //this is the section i dont understand.

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

}
}


#2

The syntax for return is incorrect in your code
It is like:

return("paper wins");

Not like:

return"paper wins"

correct it in all your code


#3

still doesnt work.

am i supposed to have an If statement above the else if statement?

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

}
}
//if statement here? if so, i dont know which one to put
else if (choice1 === "paper") {

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

}
}


#4

don't need parentheses like

return (somthing)

the main problem is you already closed your function.

if(choice2 === "scissors") {
return"rock wins";
}
else
{
return"paper wins";
}
}
}  //remove this }

you have to close function after closing second else if.

else if (choice1 === "paper") { 

if (choice2 === "rock") {
    return"paper wins";
}
else {
    return"scissors wins";
}
}
  //here you should close your function //so add }

now after this you have to call the function by function name and give arguments inside the parameter.like

functionname(arg1,arg2)

#5

thank you so much! finally got it!


#6

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