Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created May 11, 2020 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFFail/797003f14dcf362ecd65fd6e6c4fac4a to your computer and use it in GitHub Desktop.
Save JFFail/797003f14dcf362ecd65fd6e6c4fac4a to your computer and use it in GitHub Desktop.
Simple chessboard-generating script from Eloquent JavaScript Chapter 2.
var size = 15, base = "";
for(var i = 1; i <= size; i++) {
if(i % 2 === 1) {
for(var k = 1; k <= size; k++) {
if(k % 2 === 1) {
base += "#";
} else {
base += " ";
}
}
} else {
for(var k = 1; k <= size; k++) {
if(k % 2 === 1) {
base += " ";
} else {
base += "#";
}
}
}
if(i < size) {
base += "\n";
}
}
console.log(base);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment