6.What if choice 1 is rock?


#1

I can't seem to move beyond this point. Can anyone figure out what the problem is?

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

}

#2

In your first if statement, remove the semi-colon and add an open bracket at the end of the line.
Also, the return value below that doesn't need to be in parenthesis, but DOES need a semi-colon to end the line.
Finally, you'll need 1 more closing bracket at the end of your code and don't forget the semi-colon.


#3

To further expand what @methodsurfer73405 already correctly mentioned:

Here are some more information about the semicolon after the condition:


#4

It appears the system does not explain things exactly as it should. That's why people are getting stuck. At least not to the benefit of a novice coder. Thanks for your help


#5

Thanks for your help


#6

Can you show your code? I am stuck :confused:Thanks! :smiley:


#7

Post your code and I can help you from there. Let's take a look at which parts you are stuck on.


#8

maddepadde123, after looking at the code on your profile page, I would say you need to add a semicolon after your ... return "The result is a tie!" ...
You might need more, but try that first.


#9

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


#10

its the last part im having problem with now.. The first part solved out good some how..:smiley:


#11

get a bit more consistent in where you use {}. I'd suppose that this }:

else if (choice1 === "rock") 
if (choice2 === "scissors") 
return "rock wins";
else 
return "paper wins";
} //this one

closes the function, but so that the next else if is not connected to the rest. just a guess as I can't see the opening one.


#12

can someone tell me whats wrong here? i keep getting this error:
Oops, try again. Your code returned 'paper wins' instead of 'rock wins' when the inputs are rock and scissors

heres my code: 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"
    };

};

};


#13

please help me out guys... I am stuck here for quite a while, getting frustrated


#14

I think your {} do not have matches, i just figured this problem out lol


#15

@killerdraago You have too many semicolons here:

      return "paper wins"
    };// not necessary
};// not necessary

Also take your error message seriously. For an input of compare("rock","scissors") you get an output of paper wins, why?

typo

missing "s" on scissors

@geogolden Your function closes to early also copyable code would be favorable
@geogolden & @killerdraago & many others please post your own question if it is not related to the topic instead of hijacking other peoples questions. This way they just become unreadable.


#16

remove the semicolons, except for the one that's closes your function.