Issues with syntax in complex if/else statements


#1

Here's my code:

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    else if (choice2 === "scissors") {
        return "scissors wins";
    }
    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            return "paper wins";
        }
        else {
            return "scissors wins";
        }
    }
    else {
        return "rock wins";
    }
};

I can't, for the life of me, understand why this passed. The important bit that I had to change before the site would tell me it was correct, was the second return:
else if (choice2 === "scissors") {
return "scissors wins";

I originally had "rock wins", which I'm pretty sure just carried over from the previous exercise, since it tells you to start new code under the preexisting code (unfortunately, this was also incorrect, as I had to insert this new else if / if statement before the original else...).

Mostly I don't understand why scissors should win if choice1 is not equal to choice2. Why does that have to be scissors winning? The error that appears when I have it set to "rock wins" is "Your code returned "rock wins" instead of "scissors wins" when the inputs are paper and scissors" except that way up at the beginning of the if/else monstrosity, neither inputs have yet been specified.

Am I just bad at logic? Is there something wrong with the page when it tells me to begin the code after the original if / else statement? This was the original code that passed me from the previous exercise to this one:

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    else if (choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
};

Why can't I just append

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

#2

I just finished the entire rock, paper, scissors game and here's a copypasta of my code, which apparently passes:

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

The problem is, I just ran the code and computerChoice was paper, and userChoice was rock. It told me that rock wins.

How about that.


#3

Its messed up for me as well. I actually did the full working program but it's telling me that it should be returning undefined


#4

Well that sucks, but at least I know it's not just me. I wish I could understand what could be wrong with the way that lesson was coded. That would be a great way to learn.