I'm working through Eloquent Javascript and just did the examples in chapter 2. One is to create a chess board grid of arbitrary size. My code works, but the if/else if statements I used feel clunky. This is a common feeling I have when I'm writing code, but I'm often at a loss of how else to do it.
How could I write this code in a more compact, elegant way (recognizing the subjectivity of "elegant")?
http://eloquentjavascript.net/02_program_structure.html
var size = 8;
var result = "";
for(var i = 0; i < size; i++) {
for(var j = 0; j < size; j++) {
if(i !== 0 && j ===0){
result += "\n";
}
else 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 += "#";
}
}
}
console.log(result);