Yes, the contains
selector is wrong for your purpose. As the name suggests it matches any element that contains the specified text as a substring, not only those elements where there's an exact match.
You could try using .filter()
:
var matchingElements = $('span').filter(function(index) {
return $(this).text() === user_choice;
});
if(matchingElements.length === 0) {
...
}