What if choice1 is rock?


#1

I don't know where I'm going wrong with my curly brackets they got me all mixed up and it keeps telling me syntax error

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

}
}

Replace this line with your code.


#2

I'm pretty sure you just need to add one more curly bracket at the end.

It should look like this.

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

Also for future reference please put all your code inside the preformatted text.

If that helped please mark my reply as the solution.


#3

it is saying my return statement is outside of function.


#4

Please copy and paste your updated code so I can have a look.


#5

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

}

}


#6

This bit is slightly wrong.

var compare = function(choice1, choice2){
};

Everything below this code should be inside the functions curly bracket. so remove this }; and your good to go.


#7

thank you sir much appreciated


#8

Anytime friend. I love working out problems.


#9

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