Stuck at 6


#1

I’m stuck at 6



Replace this line with your 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";}
}


#2

What error message are you getting?


#3

SyntaxError: Unexpected token else
Expected an indentifier and instead saw "else"
Missing “;” before statement


#4

Ah, okay. I think this means there’s a couple of different problems in the code. I tweaked it a little bit and I think I may have fixed it.

var compare = function (choice1, choice2) {
  if (choice1 === choice2) { //missing opening bracket
    return "The result is a tie!";}

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

The first issue, Unexpected token else was because you are missing a couple of curly brackets. There should be an opening curly bracket at the end of line 2 and a closing curly bracket at the end of line 6. Also, I don’t think you need the semicolon in line 2.

The second issue is on line 4. You’ve used else if statement when it ought to be just an if statement. Try using the amended code above and let me know if you’re still having any problems.

All the best.


#5

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