Skip to content

Instantly share code, notes, and snippets.

@ralphking
Created February 18, 2015 11:05
Show Gist options
  • Save ralphking/9265cf964b4002b91b39 to your computer and use it in GitHub Desktop.
Save ralphking/9265cf964b4002b91b39 to your computer and use it in GitHub Desktop.
JS chess board. Useful for two dimensional loops
// set your board size
var size = "64";
// initialize empty string
var string = "";
// loop the sucker
for (var i = 0; i < size; i++) {
for (var j = 0; j < size; j++) {
if ((i + j) % 2 == 0) {
string += " ";
} else {
string += "#";
}
}
string += "\n";
}
// print out your chess board
console.log(string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment