4/7 Choice 1 is paper


#1

The instructions are

Inside the compare() function under the existing code, write another else if statement where the condition is choice1 === "paper".
Inside this else if statement, write an if / else statement. If choice2 === "rock", return "paper wins". Else, return "scissors wins".

People on other example start with Rock which is not the intructions.. why? Also they seem to put exercises that are not the right number. This is the instructions to part 4/7 but people have submitted code from later exercises. Well confused.

Error code says "your rode returned "paper wins" instead of "scissors wins" when the inputs are paper and scissors"

Here is my code: 

var userChoice = prompt ("Do you choose rock, paper or scissors?")
function compare (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");}}

#2

Try writing your function like this

var compare = function (choice1, choice2)


#3

Thanks for trying.. no different. is it because I included the userchoice from the previous exercise?


#4

Well, if you had also formatted the code properly, I could have also seen a few things better. But, by the instruction which you highlighted, you should do this:

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

#5

Don't put a semi colon here.


#6

Thank you both :). that did it. This is only my first day so still getting my head around it.