I need help on this step please "What if choice1 is paper?"


#1

I am having problem with the syntax

var compare = function (choice1, choice2) {
    if ( choice1 === choice2 )
    return "The result is a tie!";
else if (choice1 === "rock") {
    
    }
else if ( choice2 === "scissors" ) {
    return "rock wins";
    }
else {
    return "paper wins";
    }
else if ( choice1 === "paper" )
if ( choice2 === "rock" ) {
return "paper wins";
}
else {
    return "scissors wins";
    }
};

Here's a screenshot of the instruction.


#2

yea, you indeed have a bit of a syntax problem. Inside your function you have an if statement (to check if the choices are the same) then 3 else ifs (at the moment just two, you build the third one in the next exercise)(to check what choice1 is) inside each else if you should have an if and a else. which gives you something like this:

var compare = function (choice1, choice2) {
    if ( choice1 === choice2 ){
       return "The result is a tie!"
   }
   else if (choice1 is rock){
      if (choice2 is scissors){return rock wins}
      else {return paper wins }
   }
   else if(choice1 is paper){
       if (choice2 is rock){ return paper wins}
      else { return scissors win }
   }
}

the above is pseudo code, to give you an idea what it should look like. Yours doesn't really look like what i did above. Make sure you nest everything right, and pay good attention to the curly brackets


#3

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