First of all, your code has a little flaw. It will print the first two lines like this: ◼◻◼◻◼◻◼◻ ◼◻◼◻◼◻◼ You may haven't noticed it, because it's hard to spot using a whitespace. This happens, because you use an `else if` after prepending the newline: if (i !== 0 && j === 0) {} else if {} else if {} Remove the first `else` branch it will work. Personally, I would move this part to the end of the loop, as it reads more like: > If the line is completed, append a line-break. This test should be sufficient and is maybe easier to read: if (size - 1 == j) { result += "\n"; } To take it even a little further, move this out of the inner loop and get rid of the test at all. As you always are going to append a line-break after each row, this is sufficient: result += "\n"; <sup>Thanks to [200_success](https://codereview.stackexchange.com/users/9357/200-success) for pointing that out.</sup> <hr> Then you want to print a field of the chessboard in any case. So the second test is actually redundant: if ((j % 2 === 0 && i % 2 === 0) || (j % 2 === 1 && i % 2 === 1)) { result += " "; } else if((j % 2 === 0 && i % 2 === 1) || (j % 2 === 1 && i % 2 === 0)){ result += "#"; } … can become: if ((j % 2 === 0 && i % 2 === 0) || (j % 2 === 1 && i % 2 === 1)) { result += " "; } else { result += "#"; } <hr> Now, the condition is still hard to read. Let's simplify it: if (0 === (i + j) % 2) { result += "◼"; } else { result += "◻"; } This looks quite simple already. You can alternatively use the *ternary operator* and rely on JavaScript casting the result to boolean: result += (i + j) % 2 ? "◻" : "◼"; <hr> **The final result** <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js --> var size = 8, result = ""; for (var i = 0; i < size; i++) { for (var j = 0; j < size; j++) { result += (i + j) % 2 ? "◻" : "◼"; } result += "\n"; } console.log(result); <!-- end snippet -->