Still need help with this one


#1


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


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


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

    if(choice2 === "paper"){
        console.log("it a tie");
    }
    else if(choice1 === "paper"){
        if(choice2 === "rock"){
            return "paper wins";
        }
    }
        else{
            return "scissor wins";
        }

}


#2

In your code your middle if is unnecessary. Also you need to put your first else inside of of your first else if's curly brackets. Study my code and look at the differences.

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

}

If that helped and solved your problem please mark my reply as the solution. If you need further explanation or it still doesn't work not please let me know.


#3

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