7. what if choice1 is paper


#1

Guys help please...
Im getting this outcome
"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(choice2 === "scissors"){
return "rock wins";
}
}
else {
return "paper wins";
}

//when choice1 is = to paper wins

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

};


7.What if choice1 is paper? Stuck need help
#2

You're closing the function too soon. That misplaced curly brace is preventing the program from running through an entire else if/else. Also, you've given the second if/else if/else the same selection for choice1 which is why you're getting an incorrect output. For example:

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

 else if(choice1 === "scissors") {

    if(choice2 === "rock") {
        return "rock wins"; 

}
else {
    return "scissors wins"; 
}
}

};

Also, you have "paper wins" twice. :slight_smile:


#3

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