Counting possible moves for a queen
What about defining checkDelta?

function checkDelta(dx, dy) {
    if (0 &lt;= x + dx &amp;&amp; x + dx &lt; boardSize) {
        if (0 &lt;= y + dy &amp;&amp; y + dy &lt; boardSize) {
            // And so on.


This function should make your code really simple.