Skip to content

Instantly share code, notes, and snippets.

@Dylan-Thomson
Last active June 5, 2017 17:42
Show Gist options
  • Select an option

  • Save Dylan-Thomson/1810fec1d5af80ee1c2761f9094d604e to your computer and use it in GitHub Desktop.

Select an option

Save Dylan-Thomson/1810fec1d5af80ee1c2761f9094d604e to your computer and use it in GitHub Desktop.
ChessBoard - Eloquent JavaScript Chapter 2 Solution
function chessBoard(size) {
var board = "";
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if ((x + y) % 2 == 0)
board += "#";
else
board += " ";
}
board += "\n";
}
return board;
}
// Output for chessBoard(8)
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
// # # # #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment