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` when appending the newline: if (i !== 0 && j === 0) {} else if {} Simply separate the two statements and it will work. Personally I would move this part to the end of the loop, as it reads like: > If the line is complete append a line-break. Also, this test should be sufficient and is maybe easier to read: if (size - 1 == j) { result += "\n"; } <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 to this: if (0 === (i + j) % 2) { result += "◼"; } else { result += "◻"; } This is now so simple, that you could easily use the *ternary operator* and rely on JavaScript casting the result to boolean: result += (i + j) % 2 ? "◻" : "◼"; <hr> This will be the 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 ? "◼" : "◻"; if (size - 1 == j) { result += "\n"; } } } console.log(result); <!-- end snippet -->