Your code returned 'paper wins' instead of 'undefined'


Hi there, I hope you can help a bit with this, cause I cannot see it through.

The code seems to work very well, the game works and all is fine, except for the fact that I get this unexplicable error: "Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and paper".

Here is my code:

var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log("Me: " + userChoice);
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";}
    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 "paper wins";}
compare(userChoice, computerChoice);


Not saying it's wrong, but you don't necessarily need if (choice2)


Hi in 8. What if choice1 is scissors? your else statement the instruction says

b. if choice2 === "paper", then "scissors" wins.
so the last else statement

else {return "paper wins";}

schould return "scissors wins"


The lesson is n. 8. "What if choice1 is scissors?"


Marcos got it. Hopefully that fixes any issues.


Wow! It worked!! Thanks a lot guys!


yes but did you read my all my post ?


Yes I did. Still trying to understand why it worked though


Read b.

if choice2=== "paper" then "scissors" wins
It shouldn't be paper wins it needs to be scissors in order for it to work.


Yeah, was just re-reading all and figured it out. My way could not possibly have worked....


Always read the instructions carefully, it helps. Good luck!


you could find out why it gave you an error on that discussion..
on the third post