What if choice1 is paper? Syntax error


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#


I keep getting an error saying there is a problem with my syntax. I have even gone to other threads with people having the same issue, and looked there for help but still no luck. Can someone please tell me what is wrong with my code?


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";
    } else if (choice1 === "paper"){
        if (choice2 === "rock") {
            return "paper wins";
        } else {
            return "paper wins";    
        }
    }
}


#2

here:

else if (choice2 === "scissors")

this should be checking if choice1 is rock (you made it in the previous exercise), then inside else if you nest an if and else to check for possible scenarios of choice2:

else if (condition){
     if (condition){

    } else {
  
    }
}

see how if and else are nested inside else if? Once else if is closed, you can move on to next else if to check if the user might have chosen paper


#3

I still don't think I'm doing this correctly. Now I'm getting an error that says the code returns 'paper wins' instead of 'scissors wins'.

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

I've even gone through where you've helped others on this exact same problem and nothing. This is the most stuck I've been on any coding problem, but I appreciate you taking the time to help everyone!


#4

here:

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

when choice2 is scissors, and choice1 is paper (else), you return paper wins. Last time i played this game, scissors beats paper


#5

Right! How did I keep missing that? Thank you!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.