Each time the function gets run, new check
and error
variables are initialized. In order for them to keep state, you need to put them in a higher (such as global) context.
EDIT: For example:
var error = 0,
check = 0,
letterArray = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
$("img").click(function(){
var clickedValue = $(this).attr('name');
alert(check);
if(clickedValue ==letterArray[check]){
$(this).parent().empty();
check+=1;
} else {
error+=1;
$("error").add('<td><img src="images/xmark.png" alt="xmark" name="xmark"/></td>');
// $("error") looks like the wrong selector. You're also misusing .add()
}
});