Still need help... rock,paper, scissors


#1

Need best advice because im still stuck and i may needs some help with curly brace


#2

heres my code:

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 (choice2 === "paper") {
if (choice2 === "rock") {
return "rock wins";
}
else {
return "paper wins";
}
}
else if (choice2 === "paper") {
if (choice2 === "rock") {

}
else {
    return "scissors wins";
}

}

compare(userChoice, computerChoice);


#3

Have you made sure that all of your curly braces match up with their corresponding code? One is missing.


#4

whats missing because its keep saying got '}'


#5

is this the problem

return "paper wins";


#6

your function:

var compare = function(choice1, choice2) {

doesn't have a matching closing curly bracket (})


#7

Hmm, I see some other issues. Take a look at your syntax here:

Also, check your else ifs. They should have choice1s instead of choice2s.


#8

@biff75 and @stetim94 can you please break it down


#9

also @stetim94 i tried your example, it worked for my past code


#10

If you need more help, please post an updated version of your code


#11

what does that mean, change it


#12

Here's my different code, i tried:

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

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

compare(userChoice, computerChoice));

#13

else {return "rock wins";}
// missing a } here to end your compare function

compare(userChoice, computerChoice));  // extra ) here

#14

did it work for you, it did not work for me


#15

@albionsrefuge was it hard to do this


#16

It would be helpful if you posted all of your updated code instead of just a few lines.


#17

Okay

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

#18

it still gives the same error


#19

I've tidied up your code which is something that you should get used to doing because it makes it a lot easier to spot missing { }, ( ) , ; , etc.

I've left you comments where there is either something to be removed or something to be added.

var compare = function(choice1, choice2) {
  if(choice1 === choice2) {
    return "The result is a tie!";
  }
  else if (choice1 === "rock") {
    if (choice2 === "scissors") {
      return "rock wins"; 
    }  // unwanted } here
    } else {
      return "paper wins"; 
    }  // unwanted } here
    }
  }
  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";
    // missing } to close else
  // missing } to close else if
// missing } to close compare function

compare(userChoice, computerChoice);

#20

what am i supposed to do here
// missing } to close else
// missing } to close else if
// missing } to close compare function