Rock Paper Scissors Level 7


#1

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

}

I keep getting this error message and I am not sure why. I keep going over the logic and it seems correct. Am i missing something?


#2

What is the error tell us that first bub


#3

I forgot the error message:

Oops, try again. Your code returned 'paper wins' instead of 'scissors wins' when the inputs are paper and scissors


#4

does it say anything else in the console on the right like "syntaxerror blah blah blah"


#5

No. Just that message. I'm pretty new but the inputs are never paper and scissors. The scissors return is the "else"


#6

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!"
}
}
}
That should work


#8

I'm trying it right now. Thanks so much.


#9

no prob anytime :+1:


#10

if i doesn't work though, tell me


#11

I am doing the "dance of joy". I have been fighting with this for several days! Thanks. Where are you from?


#12

Washington in the good old northwest


#13

Across the country! Maybe we'll meet again on codecademy.


#14

I hope so! :blush:
`


#15

In case you wonder why your code doesn't work the reason is this semicolon over here:

else if (choice1 === "paper") {
    if (choice2 === "rock"); <--

Here I tried to explain why this is a problem:

Also be careful with your {} because in the same region you closed the else if so that the else is now the alternative for the else if whereas it should be the alternative to the if:

Correct structure:

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

incorrect structure:

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

#16

OK, so, I was excited that the website let me continue to the next lesson, but the more I work on this, I noticed that when I run the program, the response is (for example) computer: scissors. It does not, however, state who wins. I added console.log("rock wins"); to the program but I am not getting the winner.


#17

//try writing under

{
console.log("rock wins!")
}
//like this:
{
console.log("Rock wins!")
confirm("Rock wins!")
return "Rock wins!"
}
// you can leave out the confirm if you want, but i like how it more directly notifies you.
// add that to paper and scissors and it should tell you directly who wins, and if you don't like the way it says it you can change it to, for example, "Rock beats Paper!" or something. it is up to you! :blush: