The boundary test:
if (x > 0 && y < 6) { //bottom right
isn't right, the x condition should be x < 7
; it's the right hand column you are trying to avoid not the left.
To avoid all that duplication (and subsequent likelihood of a trivial copy-paste-edit error like this), I recommend doing the position calculation in x/y co-ordinate terms and then calculating the cell index from there instead of working in cell indices and checking each boundary separately. And actually, tables have rows
/cells
properties so you don't have to do the cell index calculation either. For example:
var knight_moves = [[-1, -2], [1, -2], [-2, -1], [2, -1], [-2, 1], [2, 1], [-1, 2], [1, 2]];
for (var i= knight_moves.length; i-->0;) {
var other_x = x + knight_moves[i][0];
var other_y = y + knight_moves[i][1];
if (other_x>=0 && other_x<8 && other_y>=0 && other_y<8) {
var cell = table.rows[other_y].cells[other_x];
if (cell.innerHTML=='♞') ...
}
}