Your compare function does not return 'The result is a tie!' when there is a tie


#1

Hi
I have the code below and always getting the error, but on the screens i get the message "The result is a tie"

Error
Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie.

Code
var compare = function(choice1,choice2) {
if (choice1 === choice2) {
return "The result is a tie";
}
};

compare("rock", "rock");

Regards,
Vitor Neves


#2

Hi again

Just discover that if the message isn't equal to the exercise, this doesn't work.

Regards


#3

Missing an ! At the end of your string.


#4

Mine isn't working either:
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "This result is a tie!";
}
};
compare("rock", "rock")

and this pops up:
Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie.
The output box says "This result is a tie!"


#5

Please explain why the desired output not coming when we do not put ! in the string?


#6

Because the code academy program is looking for a very specific string. If your string does not match, it's going to give you an error. This may simply be a lack of dept to the result check, or this could be a way of emphasizing the importance of accuracy when coding. You must be able to:
-write code with correct syntax
-catch errors
-troubleshoot errors


#7

The returned string is missing the exclamation point. ...tie! I ran into the same issue.


#8

First of all it's not very polite to hijack a thread for your own question (rather open an own one) and secondly read closely, both the answers and the error messages:

Just discover that if the message isn't equal to the exercise, this doesn't work.

Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie.
The output box says "This result is a tie!"


#9

Thank you to all for taking time to answer my query.