Rock paper scissors part 7 what if choice1 is paper


#1

else if(choice1 === "paper") {

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

return "scissors wins"
}
}
};

What is wrong w/ my code?


#2

Could you post your whole code? It may be that the problem resides in other areas in your code, as I do not see the problem with what you have provided (Assuming you have this wrapped in a function which hasn't been added here).


#3

/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/
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"
}
}
};

Here's my whole code. BTW it says SyntaxError: Unexpected token else


#4

else {
 return "paper wins";
}
}
}; /*You're closing your function here, the next else if is by itself and throwing 
the error to the console*/

else if(choice1 === "paper") {

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

#5

where should i close it then???


#6

Actually funny enough is you already have it closing where it's suppose to close, you simply have an extra closing bracket " } " and semi-colon " ; " in the wrong area. I hope this helps!

else if(choice1 === "paper") {

if(choice2 === "rock") {
return "paper wins"
}
else {
return "scissors wins"
}
}
};//It's closing here

#7

It's still not working for some reason... same syntax error


#8

Could you post your updated code? Usually it's something small and all it takes is a fresh pair of eyes!


#9

/*var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);*/
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";
}
}
};


#10

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";
 }
 }
 }; //Once again, Delete this " }; " It is the error in your code!

else if(choice1 === "paper") {

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

#11

Thanks it worked now! Stuck on it the whole day...