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


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

Any help is appreciated.


#2

The else needs to return "scissor wins"
Why? You're telling the computer if choice1 (the user) is rock, and choice2 (the computer) is scissor, then rock wins. Rock crushes scissors, we all know that.
The problem is in the else statement, else paper wins. But no one choose paper. The user chose rock and the computer chose scissors.


#3

Thats ok the inner if for choice2 deals with scissors the end deals with paper and the tie case deals with rock so everything should be fine. The problem is that there is a typo: "scissor" instead of "scissors" the s at the end is missing. So this case is not chosen although the computer picked it that's why you end up at the default "paper wins" which is obviously not suitable here.


#4

Thanks again, you seem to be really efficient in finding bugs in others code.
Do you mind sharing how long you've been coding?
Any tips for someone brand new to coding?
Any career suggestions?
Thanks again!


#5

3 or 4 years but it's more a hobby than a profession so I'm not the one with the career suggestions sry. For general hints I don't know get a good grasp of the basic concepts and then you might target small projects e.g. when codecademy had groups we made this one:
http://boring12345.github.io/Memory/
Which involved a lot of researching how the ideas in your head can be translated to code. Practice makes perfect and finding bugs is easy when you spend time finding them in your own code :smile:


#6

I just spend about 30 minutes playing this :sweat_smile: