Syntax error "else" for rock paper scissors code


#1



Im getting a syntax error, i've fooled with the code a bunch and unexpected token else is occurring.


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


#2

@medicgaming,
If you use the code

 var compare = function(choice1,choice2) {  <<==FUNCTION-BODY opened
     
     if (choice1 === choice2) {
          //IF code-block started
          return "The result is a tie!";
         //IF code-block is closed 
     }
  };    <<== FUNCTION-BODY is closed !!!!

All the following code is NOT seen as being part of the =compare= function

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#3

ok so if i remove the last bracket then add one on the end of the code to make the entire thing one function. i get unexpected token {. i understand the early one closing off the rest but now i'm confused


#4

@medicgaming,
Display the FULL code you are using now...