I am attempting to assign the appropriate class to a group of elements, representing each letter in the alphabet. The elements have IDs ranging from #alpha_0 to #alpha_25. If a letter appears just once in the input, it should be displayed in green. If a letter appears more than once, it should be red. If a letter does not appear at all, it should remain black.
The code snippet provided below is an initial attempt that currently has some flaws.
var isPangram = function() {
var s = $('#input').val().toLowerCase();
console.log(s);
var alpha = letters[getAlphabet()].join('');
console.log(alpha);
var len = alpha.length;
for (var i = 0; i < len; i++) {
if (s.indexOf(alpha.charAt(i)) != -1) {
if ($('#alpha_'+i).hasClass('green')) {
// already matched, change to red
} else {
// not yet matched, change to green
}
} else {
// no match found
}
}
}