What if choice1 is scissors?

#1

Can someone help me I have never seen the message of illegal return before and I have tried everything to fix it.

SyntaxError: Illegal return statement

``````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";
}
if (choice1 === "paper") {
if (choice2 === "scissors") {
return "scissors wins";
} else if (choice2 === "rock") {
return "paper wins";
}
}
}
}
if (choice1 === "scissors") {
if (choice2 === "rock") {
return "rock wins";
}
else if (choice2 === "paper") {
return "scissors wins";
}
}
}
};
console.log(compare(userChoice,computerChoice));``````

Lesson 8 - What if choice1 is scissors? need help!
#2

Go back and look at the hint in the exercise.

Your `else if` statements should look like this:

else if (choice1 === "something"){
if(choice2==="other"){
return "blank wins";
}
then the nested else
else {
return "other wins";
} this curly brace wraps the nested else
} this curly brace wraps the else if for choice1

Don't forget one final brace to close the compare function after all your code blocks are complete.

#3

the syntax should look like:

``````if (condition) {
// do something
}
else if (condition) {
if (condition) {
//do something
}
else {
// do something else
}
}``````

and

``````if (choice1 === "paper") {
if (choice2 === "scissors") {
return "scissors wins";
} else if (choice2 === "rock") {
return "paper wins";
}
}
}
}  // you already closed function here``````

and after closing function you need to call the function

#4

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