Lesson 8, I'm stuck


#1

What is wrong here? I really can't find it :frowning: Thanks a lot for your reply!
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";
}
else if (choice1 === "scissors") {
if(choice2 === "rock") {
return "rock wins";
}
else {
return "scissors wins";
}
}
};
compare(userChoice, computerChoice)


#2

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";
        }
    // missing closing bracket
    else if (choice1 === "paper") {
        if(choice2 === "rock") {
            return "paper wins";
        } else {
            return "scissors wins";
        }
    // missing closing bracket
    else if (choice1 === "scissors") {
        if(choice2 === "rock") {
            return "rock wins";
        } else {
            return "scissors wins";
        }
    }
};
compare(userChoice, computerChoice)

#3

Thanks! I corrected it but now : Oops, try again. You seem to have something wrong with your code. It threw the following error: ReferenceError: userChoice is not defined
What should I do?


#4

the "userChoice" and "computerChoice" should be at the top of your code. They are the inputs , maybe you have a different name for them or you dont have them, is this the full code what you provided in the first post?


#5

I don't know why but the rest of code was with this "//" and computer didn't see that. I changed it and now works. Thanks one more time:)