What am I doing wrong?


#1

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";

} if(choice1 === "paper") {
return "paper wins";

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

} else {
return "scissors wins";
}

}


#2

What makes you say that it is wrong? Explain your expectations and what is happening instead


#3

It tells me that my code returned "rock wins" instead of "scissors wins" when the inputs are scissors and paper.


#4

Well, then you'd need to look closer at the conditions leading up to that result, right?
With the arguments (scissors, paper) or perhaps (paper, scissors), what will the program do if you execute it manually? (In your head)

If you're not sure what it'll do, you can use console.log to make the program explain to you every step that it does.

Right now it looks like your program will decide that if choice2 is "scissors" then rock wins, even though rock might not have been chosen by the other player.


#5

Can you maybe possibly reply with the proper code so that I may compare the two? This part has had me stuck for days, whereas I've been able to progress through almost everything else in a day.


#6

I think you should just read your code and consider how it differs from what needs doing.

In order to determine the winner, you need to look at both choices. But there are cases where you only look at one of them, but still pick a winner. That can't be correct in all cases.

Some cases are not reachable at all, there is for example no way to get your function to say that scissors wins.


#7

I have tried that, and nothing.

Like I said, the easiest way for me to fix my code is by comparing it. There is still educational value in comparison.