Getting the same "undefined" message


I've been stuck here for too long a time getting the same "undefined" message, I still don't quite see my error:

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 (choice2 === "rock") {
        return "paper wins"
    else {
        return "scissors wins"


Thank you!

What if choice 1 is scissors - undifined help

Well you might have a look at the hint of 6/9 to see how the else if should be constructed. But for the moment think about what output you receive for a certain input:

No matter what choice1 is (unless it is the same as choice2) paper will always win for choice2 being rock even for scissors vs rock where there is no paper involved :slightly_smiling:

And if it is not tie and not choice2 being rock, scissors will win for ... reasons... :slightly_smiling:

So summarizing the syntax is ok but the logical needs to be improved.


So....what exactly needs to be changed?
(I'm new to javascript, and have been stuck on this problem for too long)


Hi your else if statement should be like that

else if (condition) {
    if (condition) {

    else {