What is Choice 1 is Paper?


#1



So, I am completely stuck at this exercise. I have included my code for consideration. I keep getting

Oops, try again. Your code returned 'paper wins' instead of 'scissors wins' when the inputs are paper and scissors
It's KILLING ME!!!! Please help me to discover what I am doing wrong!!!! I have no clue.


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

Thanks again... super new... still learning!


#2

HI this part it's missing the open { of the if statement and also missing the closing } of the else if statement

    else if(choice1 === "rock") {
        if(choice2 === "scissors") { <--  //add this one } for open the  if statement
            return "rock wins";
        }
        else {
            return "paper wins";
        }
    } <-- add this one } for closing the else if ìstatement

here too the it's missing the open if statement and add one } at the end for closing the compare function

if(choice1 === "paper") {
        if (choice2 === "rock") { <-- #add this one
        return "paper wins";
    }
    else {
        return "scissors wins";
    }
}

} <-- #this one is for closing the compare function

then here

if(choice1 === "paper")

it should be else if instaed of if


#3

Hello @mrsmedicine,

You missing a couple of curly braces in your code... for instance the ending curly brace of the else statement in your else if (choice === "rock") . Also, your if (choice1 === "paper") should really be an else if statement. Hope this fixes it...


#4

@wizmarco Thanks!!! That worked for this one!!! But, I'm still a little unclear as to why I was missing one of the curly braces when I know that I wrote the code correctly. I just need to work harder and focus more intensely!!!! Thanks again!


#5

I'm trying to follow along with this solution as it appears to me, my code is correct but i'm still getting syntax errors. I'm guessing its a curley bracket somewhere but I just cant seem to find it even going over it multiple times.

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

#6

HI sorry I didn't answer earlier...
This part you closed teh compare function earlier so you should remove on }

    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return "rock wins";
        } 
        else {
            return "paper wins";
        } 
    }
} <-- #this one

then here you shoul add one } to close the compare function

    else if (choice1 === "paper") {
         if (choice2 === "rock") {
             return "paper wins";
        }
        else {
            return "scissors wins";
       }
   }
} <-- #add this one }

#7

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